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

#include <iostream> #include <iomanip> using namespace std; int main() { const i

ID: 3649076 • Letter: #

Question

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int Months = 12;
int rain;
int values[Months];

double total = 0;
double avg;
int largest, monthlarge;
int smallest, monthsmall, count;

char names_months[Months] = {1,2,3,4,5,6,7,8,9,10,11,12};

for (int i = 0; i < Months; i++)
{
cout << "Enter the total rainfall for " << names_months[i]<<":";
cin >> rain;

if (rain < 0)
{
cout << "Do no accept negative numbers!" << endl;
cout << "Please enter a postive number." << endl;
cin >> rain;
}

values[i] = rain;
total += rain;
}

cout << "The total rainfall for the year is "<< total << endl;

avg = total / (double)Months;
cout << "The average amount of rainfall is " << avg << endl;

for ( int month = 1; month <=Months; month ++)
{
largest = values[0];
//Find largest
for (count = 1; count < Months; count++)
{
if (values[count] > largest)
{
largest = values[count];
monthlarge = count;
}
}

smallest = values[0];
//Find smallest
for (count = 1; count < Months; count++)
{
if ( values[count] < smallest )
{
smallest = values[count];
monthsmall = count;
}
}
}
//Disply the hightest and lowest rainfall
cout << "The hightest month value is : " << names_months[monthlarge] << endl;
cout << "The lowest month value is : " << names_months[monthsmall] << endl;

return 0;
}

Explanation / Answer

please rate - thanks

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int Months = 12;
int rain;
int values[Months];

double total = 0;
double avg;
int largest, monthlarge;
int smallest, monthsmall, count;

char* names_months[Months] = {"January","February","March","April","May","June",
        "July","August","September","October","November","December" };

for (int i = 0; i < Months; i++)
{
cout << "Enter the total rainfall for " << names_months[i]<<":";
cin >> rain;

if (rain < 0)
{
cout << "Do no accept negative numbers!" << endl;
cout << "Please enter a postive number." << endl;
cin >> rain;
}

values[i] = rain;
total += rain;
}

cout << "The total rainfall for the year is "<< total << endl;

avg = total / (double)Months;
cout << "The average amount of rainfall is " << avg << endl;

monthlarge = count;
largest = values[0];
//Find largest
for (count = 1; count < Months; count++)
{
if (values[count] > largest)
{
largest = values[count];
monthlarge = count;
}
}

smallest = values[0];
monthsmall = 0;
//Find smallest
for (count = 1; count < Months; count++)
{
if ( values[count] < smallest )
{
smallest = values[count];
monthsmall = count;
}
}

//Disply the hightest and lowest rainfall
cout << "The hightest month "<<names_months[monthlarge] <<" value is : " <<largest << endl;
cout << "The lowest month "<<names_months[monthsmall] <<" value is : " << smallest<< endl;
return 0;
}