jeudi 1 novembre 2018

How is my simple if-else statement unreachable code?

Honestly am shocked I am getting an error. I'm a junior CS major and I can't get this simple program to work lol. Clion says these two lions are unreachable, yet my test cases seem to work.

Code:

#include <iostream>
#include <string>
using namespace std;

int main() {

    string s = "";
    while(s != "|") {
        int val1 = 0;
        int val2 = 0;
        cin >> val1;
        cin >> val2;
        if(val1 == val2) {
            cout << "the numbers are equal.\n";
        } else {
            cout << "the smaller value is: " << min(val1, val2) << '\n'; // Says these two 
            cout << "the larger value is: " << max(val1, val2) << '\n'; // lines are unreachable
        }
        cin >> s;
    }

    return 0;
}

Test Cases:

3 3
the numbers are equal.
f
4 5
the smaller value is: 4
the larger value is: 5
|

Process finished with exit code 0

If this code is so d**n unreachable than how come my program reached it? lol thanks for any help in advance.

Aucun commentaire:

Enregistrer un commentaire