![]() |
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" exit(EXIT_FAILURE) ; Thanks for any comments!! -Gabe |
Re: C++ if loop question
You need to use loops/.
|
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 13:23. |