#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
char answer;
question:
answer=0;
cout << "What's 2 + 2? ";
cin >> answer;
if (isdigit(answer))
{
if (answer == 4)
{
cout << "You're right!\nCongratulations!";
}
else
{
cout << answer;
cout << " is completely wrong!\n";
goto question;
}
}
else
{
cout << "Type a number, you fool!";
goto question;
}
int n;
cout << "\n\nWhat's 256 x 256? ";
cin >> n;
if (n==65536)
cout << "Wow you acctually got that right...";
else
{
loop:
cout << "You're wrong!\n";
goto loop;
}
return 0;
}
The problem is with the first if-else statement. If you put in 4 it doesn't pass the answer == 4 check and skips to say "<answer> is completely wrong!"
There is a difference between '4' and 4 (the difference is equal to '0' ).
'4' is a character, 4 is a number. The actual integer value of '4' is 52 (I think).
I suppose you're using goto for the sake of experimenting. goto is not used in modern code, you should replace it with a loop of some kind (a while loop for instance).