+ 1

Is this a bug in c/c++.. chars and strings inputs are considered as they were 0 in comparison!?

Here is the code: ***************** #include <iostream> using namespace std; int main() { int x; cout <<"Entrer your number: "; cin >> x; if(x > 0) { cout <<"Positive" ; } else if(x == 0) { cout <<"Null" ; } else if (x < 0){ cout <<"Negative" ; } else { cout <<"Invalid" ; } } /* Try to give x the value of : ghgfh it will prints Null to the screen!! the same thing as 0 or just a letter f. what is the problem?? I wrote the same pgm in c and the same issue */ //I've tried it in JS and it worked as expected!!

23rd Nov 2017, 9:10 PM
Fahem
Fahem - avatar
1 ответ
0
Finally I got the right answers here: https://io.hsoub.com/go/70469
24th Nov 2017, 2:37 PM
Fahem
Fahem - avatar