Rainfall Statistics
Write a program that lets the user enter the total rainfall for
each of 12 months (starting with January) into an array of doubles.
The program should calculate and display (in this order):
Months should be expressed as English names for months in the
Gregorian calendar, i.e.: January, February, March, April, May,
June, July, August, September, October, November, December.
Input Validation: Do not accept negative numbers
for monthly rainfall figures. When a negative value is entered, the
program outputs "invalid data (negative rainfall) -- retry" and
attempts to reread the value.
NOTE: Decimal values should be displayed using default precision, i.e. do not specify precision.
SAMPLE RUN #1: ./ETest
Make sure it will run with the correct output. Ty!
Screenshot of the code:
Sample Output:
Code to copy:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//An array of strings is initialized.
//The months are stored in the memory allocated to the string //array: months
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//initialize an array to store the rainfall of 12 months
double rainfall[12] = {-1};
//initialize a variable to store total rainfal
double total_rainfall = 0;
//initialize the variable min_rainfall to store the minimum rainfall
int min_rainfall = 0;
//initialize the variable max_rainfall to store the maximum rainfall
int max_rainfall = 0;
//Prompt the user to enter the rainfall for 12 months one by one.
for(int i = 0; i < 12; ++i)
{
cout << "Enter rainfall for " << months[i] << ": ";
cin >> rainfall[i];
//If the monthly rainfall figures are in negative numbers, the program outputs /invalid data. The value is re-read.
while(rainfall[i] < 0)
{
cout << "Invalid data (Negative rainfall) -- retry" << endl;
cout << "Enter rainfall for " << months[i] << ": ";
cin >> rainfall[i];
}
//The value of total rainfall is calculated
total_rainfall += rainfall[i];
//Calculate the minimum rainfall.
if(rainfall[i] < rainfall[min_rainfall])
{
min_rainfall = i;
}
//Calculate the maximum rainfall
else if(rainfall[i] > rainfall[max_rainfall])
{
max_rainfall = i;
}
}
//Print total rainfall
cout << "Total rainfall: " << total_rainfall << endl;
//calculate the average rainfall
double average_rainfall = total_rainfall / 12.0;
//Print average rainfall
cout << "Average rainfall: " << average_rainfall << endl;
//Print the month which has recorded minimum rainfall
cout << "Least rainfall in: " << months[min_rainfall] << endl;
//Print the month which has recorded maximum rainfall
cout << "Most rainfall in:" << months[max_rainfall] << endl;
}
Rainfall Statistics Write a program that lets the user enter the total rainfall for each of...
Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. 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. Input validation: Do not accept negative numbers for monthly rainfall figures.
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 amount. PLEASE MODULARIZED THE CODE PLEASE USE C PROGRAMMING AND ADD PSEUDOCODE
The Problem 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, the number of months above and below the average rainfall, and the highest rainfall for each quarter of the year. The Assignment Write a Java program that contains five method/functions as follows: main(). Calls the functions enterRain, rainStats, aboveBelow, and quarterlyRain. enterRain(). Uses...
Write a Python program that allows the user to 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, and the months with the highest and lowest rainfall amounts. Data: January: 8.9 inches February: 11.1 inches March: 13.4 inches April: 6.9 inches May: 8.7 inches June: 9.1 inches July: 15.9 inches August: 4.4 inches September: 3.1 inches October: 5.6 inches November: 7.8...
In Java language: Write a rainfall class that stores the total rainfall for each of 12 months of years 2015 -2017 into an 2D array of doubles. Use the text file at Actividades/Tareas link as input of rainfall data. The program should read the input data from a text file. The program should have methods that at least return the following: • Total rainfall for the years 2015 – 2017 - return a 1D array • The average monthly rainfall...
Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...
[C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...
Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5-element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...