60 487
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #24346 in C++ for Ski

Question #24346
Write a program that calculates the average rainfall for three months. The program should ask the user to enter the name of each month, such as June or July, and the amount of rain (in inches) that fell each month. The program should display a message similar to the following:
The average rainfall for June, July< And August is 6.72 inches.
Expert's answer
#include <conio.h>
#include <iomanip>
#include <iostream>

using namespace std;

const string MONTH_NUMBERS[3] = { "1st", "2nd", "3rd" };

int main()
{
string monthes[3];
double rain[3];
double average = 0;

for (char n = 0; n < 3; n++)
{
cout << "Enter the name of the " << MONTH_NUMBERS[n] << " month: ";
cin >> monthes[n];

cout << "Enter the amount of rain fell during this month (in inches): ";
cin >> rain[n];

average += rain[n];
cout << endl;
}

average /= 3;
cout << "The average rainfall for " << monthes[0] << ", "
<< monthes[1] << " and "
<< monthes[2] << " is "
<< setprecision(2) << average << " inches." << endl;

_getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions