Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

CUsersalexiAppData Local Temptlemp1 RainfallMainRunShow (2].ziptRainfalMainRunShow.exe Enter the rainfall (in inches) for month #1 : 1 Enter the rainfall (in inches) for month #2: 1 Enter the rainfall (in inches) for month #3: 1 Enter the rainfall (in inches) for month #4: 1 Enter the rainfall (in inches) for month #5: 1 Enter the rainfall (in inches) for month #6: 1 Enter the rainfall (in inches) for month #7: 1 Enter the rainfall (in inches) for month #8: 1 Enter the rainfall (in inches) for month 9: 1 Enter the rainfall (in inches) for month #18: 1 Enter the rainfall (in inches) for month #11: 1 Enter the rainfall (in inches) for month #12: 1 The total rainfall for the year is 12.63 inches The average rainfall for the year is 1.99 inches The largest amount of rainfall was 1.00 inches in month 1 The smallest amount of rainfall was 1.0 inches in month 1 9:19 AM 11/30/20172 lype here to search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

Students also viewed these Databases questions

Question

Find the orbital velocity for the earth as it orbits the sun.

Answered: 1 week ago

Question

Find dy/dx if x = te, y = 2t2 +1

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago