checkpoint 52 Write an input validation loop that asks the u
Solution
Checkpoint.
5.2 Write an input validation loop that asks the user to enter a number in the range of 10 through 25.
while(true)
{
cout<<\"Enter an integer in the range 10 - 25: \";
cin>>number;
if(number >= 10 && number <= 25)
break;
}
5.3 Write an input validation loop that asks the user to enter \'Y\', \'y\', \'N\', or \'n\'.
while(true)
{
cout<<\"Do you want to continue (Y/N): \";
cin>>repeat;
if(repeat == \'Y\' || repeat == \'y\')
{ cout<<\"Yes.\"<<endl; break; }
else if(repeat == \'N\' || repeat == \'n\')
{ cout<<\"No.\"<<endl; break; }
else
cout<<\"Invalid input. Try again.\"<<endl;
}
5.4 Write an input validation loop that asks the user to enter \"Yes\", or \"No\".
while(true)
{
cout<<\"Do you want to continue (Yes/No): \";
cin>>repeat;
if(repeat == \'Yes\')
{ cout<<\"Yes.\"<<endl; break; }
else if(repeat == \'No\')
{ cout<<\"No.\"<<endl; break; }
else
cout<<\"Invalid input. Try again.\"<<endl;
}

