+ 4

why this is not resulting in true statement?

In the following code when boo= 0,it prints false& when it is 1 it prints true,but when given any other positive number it doesn't print anything.why? i read somewhere that 0 represents false & any other positive number represents true then why it is not working https://code.sololearn.com/cb1Y50JRt9gY/?ref=app

5th Nov 2017, 2:34 PM
shobhit
shobhit - avatar
2 odpowiedzi
+ 2
It is because you're comparing 2 or any other number to true, which is 1, so your else test fails. else if (boo) will not care that boo is larger than 1.
5th Nov 2017, 2:43 PM
John Wells
John Wells - avatar
+ 1
check your mistake this run correctly #include <iostream> using namespace std; int main() { int boo ; cin>> boo; if(boo == false) cout<<"false"; else cout<<"true"; return 0; }
5th Nov 2017, 2:37 PM
Nura Programmer
Nura Programmer - avatar