My if statment isn't working (replacing 'char' using if))

It seems that my char replacement only works outside an if statement. But if I do that, I can't use an if statement.

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
#include <iostream>

using namespace std;

int main()
{
    char n1 = 254,
    A = 65,
    B = 66,
    C = 67,
    a = 0;
    cout << "Enter a number from 1-3: ";

    cin >> a;

    if (a == 1)
    {
        n1 = 'A';
    }
    if (a == 2)
    {
        n1 = 'B';
    }
    if (a == 3)
    {
        n1 = 'C';
    }

cout << n1;

}
Last edited on
try:
if(a == '1')

or:
instead of char a = 0;
change it to int a = 0;
Ah, I feel dumb. That was a really simple mistake that I have overlooked. I wasn't consistent with a. Thanks mgoetschius.
Last edited on
Topic archived. No new replies allowed.