Write program that uses nested for loops to collect data and calculate the total and average rainfall over a period of years. The average will be a result of integer division so, it will not be precisely accurate but good enough. First the program should ask for the number of years. Use the read command for all user input. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. Use the read command for all user input. After all iterations, the program should display the number of years, the total number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Sample run: rainfall.sh Enter the number of years: 1 For year 1: Enter the rainfall for month 1: 2 Enter the rainfall for month 2: 3 Enter the rainfall for month 3: 2 Enter the rainfall for month 4: 4 Enter the rainfall for month 5: 2 Enter the rainfall for month 6: 3 Enter the rainfall for month 7: 3 Enter the rainfall for month 8: 0 Enter the rainfall for month 9: 2 Enter the rainfall for month 10: 2 Enter the rainfall for month 11: 2 Enter the rainfall for month 12: 2 The number of years for this run is: 1 The total number of months for this run is: 12 The total rainfall for this run is: 27 The average rainfall per month
Write program that uses nested for loops to collect data and
calculate the total and average rainfall over a period of years. The
average will be a result of integer division so, it will not be precisely
accurate but good enough.
First the program should ask for the number of years. Use the read
command for all user input. The outer loop will iterate once for each
year. The inner loop will iterate 12 times, once for each month. Each
iteration of the inner loop will ask the user for the inches of rainfall for
that month. Use the read command for all user input. After all
iterations, the program should display the number of years, the total
number of months, the total inches of rainfall, and the average rainfall
per month for the entire period.
Sample run:
rainfall.sh
Enter the number of years: 1
For year 1:
Enter the rainfall for month 1: 2
Enter the rainfall for month 2: 3
Enter the rainfall for month 3: 2
Enter the rainfall for month 4: 4
Enter the rainfall for month 5: 2
Enter the rainfall for month 6: 3
Enter the rainfall for month 7: 3
Enter the rainfall for month 8: 0
Enter the rainfall for month 9: 2
Enter the rainfall for month 10: 2
Enter the rainfall for month 11: 2
Enter the rainfall for month 12: 2
The number of years for this run is: 1
The total number of months for this run is: 12
The total rainfall for this run is: 27
The average rainfall per month is: 2
Trending now
This is a popular solution!
Step by step
Solved in 3 steps