I\'m a newbie to c++ so i\'m using simple code. Most of the other answers are ov
ID: 3642945 • Letter: I
Question
I'm a newbie to c++ so i'm using simple code. Most of the other answers are over my head so here's the code i have so far. I don't know haw to do the average and highest and lowest functions.//stores monthly rainfall amounts
//displays monthly rainfall amounts
//or total annual rainfall amounts
//or average rainfall amounts
//or hightest amount
//or lowest amount
//created/revised by Nathaniel Toler on 5/3/2012
#include <iostream>
using namespace std;
void displayMonthly(double []);
void displayTotal(double []);
void displayAverage(double []);
void displayHighest(double []);
void displayLowest(double []);
int main()
{
int choice = 0;
double rainfall[12] = {0.0} ;
for (int x = 0; x < 12; x += 1)
{
cout << "Enter rainfall for month " << x + 1 << ": ";
cin >> rainfall[x] ;
}
do
{
cout<< end1;
cout << "1 Display monthly amounts" << endl;
cout << "2 Display total amount" << endl;
cout << "3 Display average amounts" << endl;
cout << "4 Display highest amount" << endl;
cout << "5 Display lowest amount" << endl;
cout << "6 End program" << end1;
cin >> choice;
if (choice == 1)
displayMonthly(rainfall);
else if (choice == 2)
displayTotal(rainfall);
else if (choice == 3)
displayAverage(rainfall);
else if (chouce == 4)
displayHighest(rainfall);
else if (choice == 5)
displayLowest(rainfall);
} while (choise == 1 || choice == 2 || choice == 3 || choice == 4 || choice 5) ;
return 0;
}
//Function definitions
void displayMonthly(double rain[])
{
cout << "Monthly rainfall amounts:" << endl;
for (int x = 0; x < 12; x += 1)
cout << rain[x] << end1;
}
void displayTotal(double rain[])
{
double total = 0.0;
for (int x = 0; x < 12; x += 1)
total = total + rain[x];
cout << "Total rainfall: " << total << endl;
}
Explanation / Answer
void displayAverage(double rain[]) { double avg = 0.0; double total=0.0; for (int x = 0; x < 12; x += 1) total = total + rain[x]; avg=total/12; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.