Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the question: Write a program that lets the user enter the total rainfal

ID: 3547765 • Letter: H

Question

Here is the question:  

Write a program that lets the user enter the total rainfall for each of twelve months into an array of floats.  The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the highest and lowest amounts.  (The problem in the text requests the month with the highest and lowest amounts, but I am only asking for the amounts.)


The program should have 2 parallel arrays.

const int MONTH = 12;

float rainfall[MONTH] ;

string month[MONTH] = {

Here is the question: Write a program that lets the user enter the total rainfall for each of twelve months into an array of floats. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the highest and lowest amounts. (The problem in the text requests the month with the highest and lowest amounts, but I am only asking for the amounts.) The program should have 2 parallel arrays. const int MONTH = 12; float rainfall[MONTH] ; string month[MONTH] = {"Jan", "Feb".................... Display: All values should be to the nearest hundredth with trailing zeros displayed. Requirements: getMax function. The function should take 1 float array and 1 int (size) as input parameter and return the max value found from the array. Feel free to add additional parameters if needed getMin function. The function should take 1 float array and 1 int (size) as input parameter and return the minimum value found from the array. Feel free to add additional parameters if needed calcAverage function. The function should take 1 float array and 1 int (size) as input parameter and return the average value found from the array. getInput function. The function should take 1 int (size), 1 float array and 1 string array as input. The function should display the month's name and prompt user to enter the rainfall amount for that month. The values of rainfall cannot be less than 0. The function should be void.

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;


//Function to get Maximum Value

float getMax(float rainf[], int size)

{

int counter=0;

float maxVal = rainf[counter];

while (counter < size)

{

if (maxVal < rainf[counter])

{

maxVal = rainf[counter];

}

counter ++;

}

return maxVal;

}


//Function to get Minimum Value

float getMin(float rainf[], int size)

{

int counter=0;

float minVal = rainf[counter];

while (counter < size)

{

if (minVal > rainf[counter])

{

minVal = rainf[counter];

}

counter ++;

}

return minVal;

}


//Function to calculate Average Value

float calcAverage(float rainf[],int size)

{

int counter=0;

float avgVal = 0.0;

while (counter <size)

{

avgVal = avgVal + rainf[counter];

counter ++;

}

avgVal = avgVal /size;

return avgVal;

}


//Function to get raunfall Values from the User

void getInput(float rainf[], int size, string mon[])

{

int count = 0;

cout<<"Please Enter the total rainfall for the following months :"<<endl;

while (count < size)

{

cout<<"For "<<mon[count]<<": ";

cin>> rainf[count];

count ++;

}

}


int main()

{

// Variables Declaration and Initialization

const int MONTH = 12;

float rainfall[MONTH];

string month[MONTH]= {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

float maxVal, minVal, avgVal, totVal;

//Calling Function and Finding values

getInput(rainfall, MONTH, month);

maxVal = getMax(rainfall,MONTH);

minVal = getMin(rainfall,MONTH);

avgVal = calcAverage(rainfall,MONTH);

totVal = avgVal * MONTH;

//To Round Values to the nearest hundreth

maxVal = (maxVal * 100 +0.5)/100;

minVal = (minVal *100 + 0.5)/100;

avgVal = (avgVal *100 + 0.5)/100;

totVal = (totVal *100 + 0.5)/100;

//Printing the Values

cout<<"Maximum Value :"<<maxVal<<endl;

cout<<"Minimum Value :"<<minVal<<endl;

cout<<"Average Value :"<<avgVal<<endl;

cout<<"Total Rainfall :"<<totVal<<endl;

return 0;

}