Question

In: Computer Science

7. Average Rainfall Design a program that uses nested loops to collect data and calculate the...

7. Average Rainfall

Design a 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 twelve 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. PSEUDOCODE

Solutions

Expert Solution

PSEUDOCODE:

/*******PseudoCode*******************/
/*
AverageRainFall
{
   Main Begin
{
       /*Variables initialization*/
       years,rfall,total=0,months=0,i,j;
       /*prompt the user to read number of years*/
       read years
       for i=0 to years
       {
           for j=0 to 12
           {
               /*prompt the user to read rainfall of month in year i*/
               read rainfall
               /*add rainfall to total*/
               total+=rainfall;
               /*increment months*/
               months++;
           }End For
       }End For
   calculate average as total/months;
   print total number of months
   print total inches of rainfall
   print average rainfall
   }End Main
}

Sample source code in c++:

Output:

Code in text format (See above images of code for indentation):

#include <iostream>
using namespace std;
/*main function*/
int main()
{
   /*variables*/
   int years,rfall,total=0,months=0,i,j;
   /*read number of years from user*/
   cout<<"Enter the number of years: ";
   cin>>years;
   /*outer loop iterates for number of years*/
   for(i=0;i<years;i++)
   {
       /*inner loop iterates for 12 months*/
       for(j=0;j<12;j++)
       {
           cout<<"Enter inches of rainfall for month "<<j+1<<" in year "<<i+1<<": ";
           cin>>rfall;
           /*calculate total and increment months*/
           total+=rfall;
           months++;
       }
   }
   /*print total months*/
   cout<<"Total number of months: "<<months<<endl;
   /*print total and average rainfall*/
   cout<<"Total inches of rainfall: "<<total<<endl;
   cout<<"Average rainfall per month for the entire period: "<<(double)total/months;
   return 0;
}


Related Solutions

Design a program that uses Nested loops to collect data and calculate the average rainfall over...
Design a 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 numbers of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each 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.
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user 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...
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user 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...
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
In this exercise we will practice using nested loops. You will write s program that prompts...
In this exercise we will practice using nested loops. You will write s program that prompts the user to enter an integer between 1 and 9 and displays a pyramid of numbers, as shown in the example below. The program must validate the input given by the user and make sure that: if the user enters a non-integer the program issues an error message and requests the user provides a valid input. if the user does not enter a number...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through the array. Each pass compares successive pairs of elements. If a pair is in increasing order (or the values are equal), the sorting procedure leaves the values as they are. If a pair is in decreasing order, the sorting procedure swaps their values in the array.  The first pass compares the first two elements of the array and swaps their values if necessary....
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops,...
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops, evaluate the multivariable function: z = sin ⁡ ( x ) cos ⁡ ( y ) for x between -4 and 4 in steps of 1 y between -2 and 2 in steps of 1 Display the matrix z Cut and paste the following into a word doc and submit to this question. Your script code Your input Your output
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics Design a program that lets the user enter the...
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall , and the months with the highest and lowest amounts. PLEASE AND THANK YOU
In Python: Design a program that lets the user enter the total rainfall for each of...
In Python: Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing...
Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Requirements You must use the given function prototypes. You can add more functions if you like. def get_total_rainfall(months, months_len): def get_average_monthly_rainfall(months, months_len): def get_month_with_highest_rainfall(months, months_len): def get_month_with_lowest_rainfall(months, months_len): Design Considerations Use a global parallel array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT