+ 1
Setting a limit
How do I set a limit for a variable that will be entered by the user using cin statement. int a; cin >> a; how do I set a limit of 40 for the value entered for the variable a
1 Answer
+ 9
int a;
do
{
cin >> a;
if (a > 40) std::cout << "Over limit! Try again\n";
}
while (a > 40);
// or simply
cin >> a;
if (a > 40) a = 40;
// proceed.