If statement not working correctly.

1
2
3
4
5
 if (floor13 == 'N' && floor13 == 'n');
                {if (nof == 13)
                     {nof++;
                     }
                } 


Ok so I ask the user earlier to cin floor13, and if they type N I want variable "nof" to get +1 when "nof" is = to 13.

But whether the user types N or Y , it gets plus 1! Why is this?

Basically how can I make it so that when NOF == 13 AND floor13 == N it gets plus 1?

Sorry if that is a bit confusing but do you get what I mean?
I don't want nof to increase unless those 2 conditions are met.
Last edited on
if (floor13 == 'N' && floor13 == 'n');
means if condition is evaluated true then do empty statement.

Remove the semicolon.
1
2
3
4
5
6
7
	if (floor13 == 'N' || floor13 == 'n')
	{
		if (nof == 13)
		{
			nof++;
		}
	}


First of all, try to write your code with a little more space and indentation. It makes it much more readable. You have a semicolon at the end of your if statement. Remove it. You also should change && to || (or). As an example, n cannot be equal to both n and N so the condition will never be met.
Cool thanks a lot it worked.
Topic archived. No new replies allowed.