4. Read the following example showing a type of while loop you have seen before,
ID: 3725188 • Letter: 4
Question
4. Read the following example showing a type of while loop you have seen before, used for input validation. Although you try to make your application's instructions as clear as possible, you know that users often will make mistakes and enter input incorrectly. Complete the code to catch the error if the user's input is not within the specified range. The user should be informed of the problem and allowed to enter the input again. int guess; printf ("Please guess a lucky integer between 1 and 10, inclusive: " scanf("%d", while( )/lout of range? printf("Sorry, 5. Do we know how many times the loop in Problem #4 will repeat? why or why not? Explain 6, what type of while loop is shown in Problem # 4 above? Circle the correct letter from the list below: a. Count-controlled while loop b. Sentinel value-controlled while loop c. Event or flag-controlled while loop d. EOF-controlled while loop e. Search-controlled while loopExplanation / Answer
Answers:-
==================
4.A)
int guess;
printf("Please guess a lucky integer 1 and 10,inclusive");
scanf("%d",&guess);
while(guess>10||guess<0)//check whether the guess in between 1 and 10 only.
{
printf("Sorry,Please try again");
printf("Please guess a lucky integer 1 and 10,inclusive");
scanf("%d",&guess);
}
5.A) Actually the Above ForLoop is Called the Event/Flag Controlled While Loop.A sentinel variable is initialized to a specific value.
The while loop continues until, through some action inside the loop, the sentinel variable is set to a predefined termination value.
i.e the Above While Loop will repeat until User give the "Guess" Number in between 1 an 10.
6.A) c.Event or flag controlled Loop.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.