Question: c++ Counter-Controlled While Loop Lab Write a program that calculates the average rainfall over a period of sevaral months. You will need to do the
c++ Counter-Controlled While Loop Lab
Write a program that calculates the average rainfall over a period of sevaral months. You will need to do the following:
- Prompts the user for the number of months they wish to compute the average over.
- Computes a running total of the rainfall amounts entered. You will need to initialize this variable to zero when you declare it.
- Calculates the average of the rainfall amounts entered.
- Test to make sure the average is not computed if the number of months is zero.
- Prints out one of the following:
- A message stating the average of the rainfalls entered.
- An error message stating that the number of months must be greater than zero.
Include the following:
1. If the User enters a zero or less for the number of months then print out an error message stating that the number of months must be greater than zero.
2. Initialize the counter to either zero or one before the while loop begins.
3. Use a counter controlled while loop that uses the number of months entered by the User as the maximum number of loops executed.
a. If you initialized your counter to zero you will want the loop to continue as long as your counter is less than the number of months.
b. If you initialized your counter to one you will want the loop to continue as long as your counter is less than or equal to the number of months.
4. Within the body of the loop:
a. Prompts the User for the rainfall amount of the each month.
b. Compute a running total of each rainfall amount as they are entered.
5. After the While Loop is done executing, compute the average of all the rainfall amounts entered. Remember to check to make sure you don't perform a division by zero.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
