Question
Write a program that lets the user enter the total rainfall for each of 12 months into an array of double s. The program should
Write a program that lets the user enter the total rainfall for each of 12 months into an array of double s. 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.
================================================================
Hints
================================================================
// Chapter 7, Programming Challenge 2: Rainfall Statistics // Constant for the number of months // Function prototypes // Array to hold the rainfall data // Get the rainfall for each month. // Set the numeric output formatting. // Display the total rainfall. // Display the average rainfall. // Now display the largest & smallest amounts. // The subscript variable will be passed by reference // the the getLargest and getSmallets functions. int subScript; // Display the largest amount of rainfall. // Display the smallest amount of rainfall. return 0; } // ******************************************************** // The getTotal function calculates and returns the * // total of the values stored in the array parameter. * // The size parameter indicates the number of elements * // in the array. * // ******************************************************** double getTotal // ******************************************************** // The getAverage function returns the average of the * // values in the array parameter. The size parameter * // indicates the number of elements in the array. * // ******************************************************** double getAverage // ******************************************************** // The getLargest function returns the smallest value in * // the array parameter, and stores the subscript of the * // largest value in the element reference parameter. * // ******************************************************** double getLargest // ******************************************************** // The getSmallest function returns the smallest value in * // the array parameter, and stores the subscript of the * // smallest value in the element reference parameter. * // ******************************************************** double getSmallest
this is supposed to be the outcome
OK this is what I have, its basically done. I just need it fixed in order to match this output above:
#include
#include
/amespace
using namespace std;
//function definitio for getTotal
double getTotal(double rainArray[], int size)
{
double total;
for(int i=0; i
{
total = total + rainArray[i];
}
return total;
}
//function definition for getAverage
double getAverage(double rainArray[], int size)
{
double sum = 0;
for(int i = 0; i
{
sum = sum + rainArray[i];
}
double Avg = sum/size;
return Avg;
}
//function definition for getWettestMonth
double getLargest(double rainArray[], int size)
{
double max = rainArray[0];
for(int i=0; i { if(rainArray[i] > max) { max = rainArray[i]; } } return max; } //function definition for getDriestMonth double getSmallest(double rainArray[], int size) { double min = rainArray[0]; for(int i=0; i { if(rainArray[i] { min = rainArray[i]; } } return min; } //start of main function int main() { //setting precision to two decimal point cout //string array initilaiztion string months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "Novemebr", "December"}; int size = 12, i; //rainArray declration double rainArray[size]; //loop for i times for(i=0; i { cout cin>>rainArray[i]; cout } //call to functions double max = getLargest(rainArray, size); double min = getSmallest(rainArray, size); int index_max, index_min; //finding the index which contains the min and max rain in the array for(i=0; i { if(rainArray[i] == max) { index_max = i; } if(rainArray[i] == min) { index_min = i; } } cout cout cout //display the report cout cout cout cout return 0; }//end of the functions Very important that my code gets fixed to look like the image I provided
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started