Question

In: Computer Science

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.

Solutions

Expert Solution

// C++ program to collect data using nested loops and calculate the average rainfall over a period of years

#include <iostream>

using namespace std;

int main() {

       int years;

       double rainfall, total_rainfall = 0;

       // input of number of years

       cout<<"Enter the number of years : ";

       cin>>years;

       // nested loops to input data of rainfall for the years

       for(int i=1;i<=years;i++)

       {

             for(int j=1;j<=12;j++)

             {

                    cout<<"Enter inches of rainfall for year-"<<i<<" month-"<<j<<" : ";

                    cin>>rainfall;

                    total_rainfall += rainfall; //calculate the total rainfall

             }

       }

       // output

       cout<<"\nNumber of months :"<<(years*12)<<endl; // number of months

       cout<<"Total inches of rainfall : "<<total_rainfall<<endl; // total inches of rainfall

       cout<<"Average rainfall per month for the entire period : "<<(total_rainfall/(years*12))<<endl; // average rainfall per month for the entire period.

       return 0;

}

//end of program

Output:


Related Solutions

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...
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....
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...
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 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. This is my Pthon 3.8.5 code so far: #Determine Rainfall Program for a 12 month Period #It should calculate and output the "total yearly rainfall, avg monthly rainfall, the months with highest and lowest amounts #list of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT