If not working in one instance - assistance required

" cout << endl << "Press X to Exit" << endl ;
cin >> r ;
if (r == !'X' or !'x' )
goto loop ;

return 0;
} "
is never going to loop
and
" cout << endl << "Press R to Repeat" << endl ;
cin >> r ;
if (r == 'R' or 'r' )
goto loop ;

return 0;
} "
is always going to loop !!
HELP PLEASE!!
Cant figure what ive done wrong, I have other ifs working in the same program, and the complier isnt saying there is an error
You can't test a conditional like:

if (r == !'X' or !'x' )

X and x are essentially codes from the ascii table.

'X' being equal to 58 and 'x' equaling 78.

So your conditional can be reinterpreted as:

if( r == !58 || ! 78 )

That ends up negating the value of those two numbers. I believe in essence, you're comparing r to 0, but it's it's been a while since I played such boolean games. In addition, a comparison requires two terms.

You need to specify it as:

if( r != 'X' || r != 'x' )

You're comparing the contents of r to a value.
Last edited on
You can test this:
while(1)
{
char answer;
cout<<"Press X to exit"<<endl;
cin>>answer;
system("cls");
if(answer=='x' || answer == 'X'){return 0;}
}
neither of them work, both looping even when x is inputed
I dont understand what you want?
Dont you want a loop that loops always if answer is not X or x?
now it always exits:

"cout << endl << "Press X to Exit" << endl ;
cin >> r ;
if( r = 'X' )
goto end ;
if (r = 'x' )
goto end ;
else
goto loop ;
end: "
Last edited on
I see but my codes works.It exits only if you enter X or x.You should try it.
stupid me forgetting double == 's
Topic archived. No new replies allowed.