Which loop (while, do-while, or for) is best to use in the following situations?
A) The user must enter a set of exactly 14 numbers.
B) A menu must be displayed for the user to make a selection.
C) A calculation must be made an unknown number of times (maybe even no times).
D) A series of numbers must be entered by the user, terminated by a sentinel value.
E) A series of values must be entered. The user specifies exactly how many.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
- C++ please! Write code with one while loop that prints out these 5 lines like this (remember a newline after each line): COUNTDOWN TO ZERO: 4 COUNTDOWN TO ZERO: 3 COUNTDOWN TO ZERO: 2 COUNTDOWN TO ZERO: 1 COUNTDOWN TO ZERO: LIFT OFF!arrow_forwardHow many times will the while loop that follows be executed if months has a value of 5?int i = 1;while (i < months) { futureValue = futureValue * (1 + monthlyInterestRate); i = i+1;}arrow_forwardmake a while loop that if user has an invalid choice of service or food choice for item, the question will repeat until the user gives a valid answer. CODING: #show the menu to the user from random import choice print("1.Carbonara 100php \n2.Fries 80php\n3.Chicken nuggest 150php") #take the choice of the item itemChoice = int(input()) #Show the delivery services print("Choose the delivery services :-\n1.Foodie panda\n2.Food deliver") #Take the input for the delivery service deliveryChoice = int(input()) #If the delivery choice is if(deliveryChoice == 1): #Check for the item if(itemChoice == 1): #calculate discount for the carbonara Discount = 100*0.01 print("You get discount of :- ",Discount,"php") print("Discounted price :- ",100-Discount,"php") #calculate the final price finalPrice = (100 - Discount)+10 print("Your final price adding the delivery charge is :- ",finalPrice,"php") elif(itemChoice == 2):…arrow_forward
- 1. Infinite loops are caused when the loop-continuation condition in a while, for or do....while statement never becomes true. A. True B. False 2. A loop that never ends is reffered to as a/an:. What it is? 3. The default label is optional in the switch statement. A. True B. Falsearrow_forwardThe purpose of using a loop is to Select one: A. Repeat operation(s) many times B. Repeat operation(s) many time and make decision C. make decision D. None of the option mentionedarrow_forward28. This looping control statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. default continue break None of the Choices Give an explanation for the answer. Thank youarrow_forward
- What is the minimum number of iterations required to exit the following loop? double vall=0; bool Done = false; while (! Done) { vall += rand () %5; if (vall>=10) Done= true; }arrow_forwarda) Request the lower bound, lower and the upper bound, upper from the console.b) Request an increment value incVal from the console.c) Use a while loop to increment from lower to upper by increments of incVal such as 0 3 6 9 12 given lower of 0and upper of 12 and increment of 3.d) Use a while loop to vertically print all values in between each increment.e) Use a for loop to vertically print all values in between each increment.arrow_forwardFor each loop, enter the number of times it will execute (if infinite, enter -999):Please enter just a number. a. for(x = 15; x > 7; x--) b. for(y = 0; y <= 10; y++) c. for(z = 2; z > 5; z++) d. for(a = 3; a < 20; a = a + 5) e. for(b = 1000; b <= 1003; b--) f. for( ; ; )arrow_forward
- A for statement is a loop that goes through a list of things. Therefore, it keeps running as long as there are objects to process. Is this a true or a false statement?arrow_forwardOnly the For…Next statement can be used to code a nested loop. True or False?arrow_forwardThis program will give the user two options – to convert centimeters to inches, inches to centimeters, or to exit. Ask the user if they’d like to convert cm to inches, inches to cm, or if they’d like to exit. If they choose to convert, ask them for their numeric input, do the math, and output the result to them. The loop should then repeat and the menu should be reprinted for them to select again. If they choose to exit, the program should end cleanly. (“Cleanly” means we do not ask for more input or do any math. However, you are encouraged to add a “goodbye” statement.) If they choose an invalid option for the menu, tell them that they entered an invalid option, reprint the menu, and let them enter again. You do not have to account for negative centimeters. Simply do the math and let a negative answer be given. Use a while loop to complete this program. Consider using an if/else statement inside your loop. Consider using a Boolean variable to control the loop. Program should be…arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning