Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Which to use? Use a while loop when you don t know exactly how many times the loop will repeat ( indefinite loop ) Use
Which to use?
Use a while loop when you dont know exactly how many times the loop will repeat indefinite loop
Use a for loop when you know exactly how many times the loop will repeat definite loop
Both these loops are pretest loops which means that if the first test fails is false then the statements in the loop body are never executed.
The do while loop is also indefinite but is post test so that loop runs the code block at least once before the first test. Every time you get input you do this. You collect data and plan to loop back only to correct it
Lab:
Just submit this document See directions below. and insert your work after each task description.
For each of the following tasks, provide the complete pseudo code including all elements that we have been using ie class, end class, main return, output prompt Be sure to declare your variables and use symbolic constants where appropriate. Determine if each task requires a definite or indefinite loop and use the correct one. Use the do while loop for loops that you want to execute at least once, like getting input.
a Task pts: an application program where the user enters the price of a series of items assume at least one.Prompt user for additional items until they are done, so we dont know ahead how many items there will be This is the looping part! ;) The program computes shipping costs. If the total price of all items is $ or more, then shipping is free otherwise it is of the price. The program should output the total price of all items, the shipping cost, and the total cost.
b Task pts: A program that prompts the user for an initial balance and a monthly interest rate and then displays each new monthly balance for a month period. Interest is compounded. Print inside the loop so you display each of the balances not just the final.
c Task pts: A program that collects a series of grades ranging until the user indicates that they dont want to continue entering values useing a sentinel value. is a good choice for a sentinel here.
The program should display the average of the grades entered.
d Task pts: Rock Paper Scissors: The game repeats as long as the user enters Y to a prompt to continue. Get a move from player A and then from player B Assume that the move is valid so it has to be one of the choices R P or S Your program should compute the winner with an appropriate output string: Rock Breaks Scissors Player A wins, etc... And then prompt to play again...
Extra Credit Options:
e Task pts: Code a number guessing game. The user picks a number between and and the computer guesses the value. Each time, the player indicates if the guess is larger or smaller by entering a plus or a minus sign. If the computer guesses the value correctly then the user enters a exclamation point Assume in this case that the playeruser it truthful.
f Task pts: A program that displays the by multiplication table. This is a bit of a challenge as it requires a nested loop so Ill grant you extra credit if you complete it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started