Chars and if-else

Hi all!
I just began programming in C and C++ and ran into a problem while making a program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
using namespace 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!"
What type is the variable "answer"???
A long one ;p
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).
Ahh thank you very much, that would explain the 52 ;P
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).
Topic archived. No new replies allowed.