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); }
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]
Last edited by manofsteel972; 09-27-2004 at 05:22 AM.
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/
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.