0
this is outputting int Q even when the if statement evaluates to false. why?
#include <iostream> using namespace std; int main() { string a ="i am learning c++!"; cout << "Hello world!" << endl; cout << a << endl; string b ="it is tedious."; cout << b << endl; string c="22x=220\n what does x equal?\n"; cout<< c; string Q="correct"; string W="false"; int qwerty; cin>> qwerty; if (qwerty=10){cout<<Q; } else {cout<<W; } return 0; }
2 Respostas
+ 4
You are assigning 10 to qwerty as you only have one =. 10 is true so you always get Q.
0
You assigned 10 to qwerty, the returned value is always true:
if (qwerty = 10)
You compare qwerty with 10. This returns true if qwerty equals 10, and false otherwise:
if (qwerty == 10)