checkpoint 5.2 Write an input validation loop that asks the user to enter a numb
ID: 3933944 • Letter: C
Question
checkpoint 5.2 Write an input validation loop that asks the user to enter a number in the range of 10 through 25. 5.3 Write an input validation loop that asks the user to enter Y, y, N', or 'n'. 5.4 Write an input validation loop that asks the user to enter "Yes" or "No 5.12 Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate the sum of the numbers entered. 5.7 You want to write a for loop that displays "I love to program" 50 times. Assume that you will use a counter variable named count A) What initialization expression will you use? B) What est expression will you use? C) What update expression will you use? D) Write the loop. 5.8 What will the following program segments display? A) for (int count 0: count 6: count++) cout (count count: B) for (int value 5; valueExplanation / Answer
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.