For some reason, the below code will not work (ie, the loop will not break out if either a 'Q' or 'q' is entered for line).
Help!Code:numelms = 81;
char line[numelms];
while (*line != 'Q' || * line != 'q')
{
cin.getline(line, numelms);
}
Printable View
For some reason, the below code will not work (ie, the loop will not break out if either a 'Q' or 'q' is entered for line).
Help!Code:numelms = 81;
char line[numelms];
while (*line != 'Q' || * line != 'q')
{
cin.getline(line, numelms);
}
[edit]
oops nevermind
[/edit]
nevermind just change it to and
try
change to &&
[explanation]Code:while(*line!='Q'&& *line !='q')
the test you have states that
it will be true if either
*line!='Q'
OR
*line!='q'
problem is that when you enter a Q or q one is true and the other is false
1 OR 0 =1; so it alwasy evaluates to be true;
if you change it to AND 1 AND 0 is 0 and the loop exits;
[/explanation]
Man, I can't believe I didn't see that... I did this kind of loop all the time and Java... it's too early to be programming man.