C++ if loop question

Newbie Member
11Feb2008,12:01   #1
gabego's Avatar
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"
exit(EXIT_FAILURE) ;

Thanks for any comments!!
-Gabe
Go4Expert Founder
11Feb2008,12:59   #2
shabbir's Avatar
You need to use loops/.
Newbie Member
14Feb2008,06:22   #3
gabego's Avatar
yea, directly after the cout , do cin again instead of exiting. That would be a loop.