PDA

View Full Version : C++ Quick Help




pknz
Aug 27, 2005, 10:18 PM
C++ Programming

How do you exit a while loop with an 'x'?
So far I have this
while(cin.good() && iCode!='x')

but if I run this and enter x, it is rejected by the fact it is not numerical
while (!cin.good() || iCode>999).

Also after a cout, how do you clear the line, I believe it is clreol(); but where do you put this to clear the line.

Thanks



VanMac
Aug 28, 2005, 08:45 AM
Here is a nice little tutorial on loops in C++
http://www.cprogramming.com/tutorial/lesson3.html

You may also want to look into the switch/case statement depending on what you are doing.

Happy Coding

SamMiller0
Aug 29, 2005, 01:08 PM
while(cin.good() && iCode!='x')


What type of variable is iCode?

I am not sure how to "clear the line" since that's platform specific. You can do it easily with a curses library, typically ncurses on Linux. As far as the mac, I am not sure. Someone will response hopefully.

pknz
Aug 29, 2005, 02:34 PM
Thanks for yor help guys.

The tutorial was quite informative.

Thanks