Ask Question
30 January, 01:06

Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order) : the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i. e.: January, February, March, April, May, June, July, August, September, October, November, December.

+1
Answers (1)
  1. 30 January, 04:52
    0
    Using c++

    Explanation:

    #include

    #include

    using namespace std;

    int main ()

    {

    //this is data declaration

    double aveRain, PeakRain, MiniRain;

    double monthlyRains[12];

    double TotalRains = 0;

    int HighMonth, LowMonth;

    //This next line is used to declare the moths of the year

    String Months[12] = { "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

    cout << "Enter the rainfall for Months" << endl;

    //This will loop through the months to get the rainfalls

    for (int i = 0; i < 12; i++)

    {

    cout << Months[i] << ": ";

    cin >> monthlyRains[i];

    TotalRains = TotalRains + monthlyRains[i]; / / This is to get the total rainfall

    }

    / / To get the average rainfall

    aveRain = TotalRains/12;

    //To get the month with the highest rainfall

    //This set the first month to highest then loops through the rest.

    PeakRain = monthlyRains[0];

    for (int i = 1; i < 12; i++) {

    if (monthlyRains[i]>PeakRain) {

    PeakRain = monthlyRains[i];

    HighMonth = i;

    }

    else{

    HighMonth = 0;

    }

    }

    MiniRain = monthlyRains[0]; / /This mark first month as the lowest

    for (int i = 1; i < 12; i++) {

    if (monthlyRains[i]
    LowRain = monthlyRains[i];

    LowMonth = i; / / This marks the month with the lowest rain

    }else{

    LowMonth = 0; / /if no lower month is found, the first month is marked as lowest

    }

    }

    //To display the answers

    cout << "The total rainfall for the year was " << TotalRains << endl;

    cout << "The average rainfall for the year was " << aveRain << endl;

    cout <<"The month with the highest rainfall was" <
    cout <<"The month with the lowest rainfall was" <
    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers