+ 2
Why this program showing the result "too young" instead of " adult" ???
#include <iostream> using namespace std; int main() { int age = 42; if (age=16) { cout<<"too young";} else if ( age=42) { cout << "Adult";} return 0; }
3 Respostas
+ 11
To check equality, you *must* use ==.
Here, you're using single =, which assigns 16 to age. Any value that isn't 0 is evaluated as true, so the first if runs.
+ 9
yw :3
+ 2
got it , thank you