Question about if statement

Hi,

I wrote the following code

int a;
cin >> a;
if(a== 2) { // btw do I need to single quote '2'
a=3;
}
else{
a=5;
}
int c=a+2;
cout << c;

And what I want it to do is this: if the user input is 2 then a is assigned to 3
otherwise a is assigned to 5. And c will be either 3+2=5 or 5+2=7. But the problem is this: no matter what input it is, the c is always 7. It's 7 even when 2 is input. Why is that?
Last edited on
Works fine for me :o
you could try to assign a as 0 when your declaring the variable

int a = 0;

Dont single quote 2 because a is a int variable. It will come up with an error.
It works fine for me too though..
Last edited on
Topic archived. No new replies allowed.