Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ if loop question (http://www.go4expert.com/forums/cpp-loop-question-t8749/)

gabego 11Feb2008 12:01

C++ if loop question
This program will terminate for an input < 0 using this particular exit() function. Is there a function or a different statement to use that will loop back to the first cout statement so the user could input a new number? In this current form, the user has to re-execute the program after making a mistake.

int p, k = 5;

cout << "enter a number greater than or equal to 0" <<;
cin >> p;
cout << p + k;
if (p < 0)
cout << "error try again"

Thanks for any comments!!

shabbir 11Feb2008 12:59

Re: C++ if loop question
You need to use loops/.

gabego 14Feb2008 06:22

Re: C++ if loop question
yea, directly after the cout , do cin again instead of exiting. That would be a loop.

All times are GMT +5.5. The time now is 08:38.