Average Rainfall Design a pseudocode program that uses nested loops to collect d
ID: 3770776 • Letter: A
Question
Average Rainfall
Design a pseudocode program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. 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. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.
Submit either a Flowchart or Pseudocode . (No java, javascript)
Explanation / Answer
Pseudocode in C:
printf("enter the number of years"); //ask the user to enter the no of years
scanf("%d",&year);
month=year*12; // convert the year to month
for(int i=1;i<=year;i++) // outer loop to iterate will iterate once for each the number of years
{
for(int j=1;j<=month;j++) // inner loop that will iterate 12 times for each year and once for a month
{
printf("enter the inches of rainfall for month %d: ",j); \ ask the user to enter the inches of rainfall for that month
scanf("%f",&rain);
sum=sum+rain; //calculate total inches of rainfall
}}
avg=sum/month; // average rainfall per month for the entire period.
printf("total month: %d ",month); //display the number of months
printf("total rainfall: %f ",sum); //display the total inches of rainfall
printf("avrg rainfall per month : %f",avg); // display the average rainfall per month for the entire period.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.