Asep Kurnia X Asep Kurnia X - 19 days ago 5
C++ Question

if cin true or false from variable C++

please help me solve this..

int A=10;

cout<<"Answer this Question!";
cout<<"5 + 5 = ";cin>>A;
if(true) {
cout<<"Correct!"<<endl;
} else if (false) {
cout<<"Wrong!"<<endl;
}

getch();

}


the answer is A=10, if user input right answer from the
int A=10
then notif use cout "Correct!" and if wrong is "Wrong!" .

M.M M.M
Answer

In your above code,

if (true)

always evaluates to true, so it will always print "Correct!". However, I am guessing you are asking how do we check the user's input to see if they are correct? In that case, for your if statement, you want

if (A == 10)

and rather than an else if, just have an else statement since any answer other than 10 would be incorrect.

I suggest you look up basics of programming.

Comments