char not staying put???

Code is too long, so I have to put it on pastebin.

http://pastebin.com/bHdwdKbM

On line 39, I put a superfluous line of code to illustrate my point. Basically, I tried making a condition where if (charInput == 'q' || 'Q'), it would break out of the loop in main. But when I did that, it would quit no matter what. Otherwise, it wouldn't quite like it was supposed to. If you look on the output of the program, you can see that it's coming up as v instead of = or ) like it should be. It seems to change to v (or perhaps something different in your case). What the heck is going on there? It shouldn't be doing that! I had to use a bool to exit the loop instead and THAT works just fine.
Problem is how you statement is parsed.
For example look at the following code: if(1)
Next statement will always execute, because al non-zero integers are evaluated as true. Char is actually is a byte type, and character code of 'Q' is not zero.

Your condition will be understood as ( (charInput == 'q') || 'Q' ) which equals ( (charInput == 'q') || true ).
With basic boolean algebra knowledge we can see that this will always evaluate to true.

Correct condition: ( (charInput == 'q') || (charInput == 'Q') )
> Code is too long
Minimize it.

> If you look on the output of the program, you can see that it's coming up as v
> instead of = or ) like it should be.
`charInput' is uninitialized.
You've got a global with the same name, but you are referring to the local one.
Topic archived. No new replies allowed.