YEARLY MONTHLY RAINFALL
Month Rainfall in inches
January ///////3.8
February ///////5.2
March///// 4.7
April/////6.3
May///3.9
June ////0.9
July////0.9
August//////2.2
September///////// 3.4
October ///////2.0
November//////// 2.0
December ////////3.7
}
// Call total
totalRain = getrainTotal (rainfallAmount, MONTHS);
outFile << "The total rainfall for the year is "<<totalRain<<" inches."<<endl;
//Call average
avg = totalRain/MONTHS;
outFile << "The average monthly rainfall is "<<avg<<" inches."<<endl;
//Call highest rainfall
mostRain = gethighestRainfall(rainfallAmount, MONTHS);
outFile << "The highest rainfall of "<<mostRain<<" occurred in April"<<endl;
//Call lowest rainfall
leastRain = getlowestRainfall (rainfallAmount, MONTHS);
outFile << "The lowest rainfall of "<<leastRain<<" occurred in June"<<endl;
outFile << "The lowest rainfall of "<<leastRain<<" occurred in July"<<endl;
outFile<<" "<<endl;
//Get months with at least 4 inches
outFile <<"Rainfall of 4 inches or more occurred in February."<<endl;
outFile <<" "<<endl;
outFile<<"Rainfall of 4 inches or more occurred in March."<<endl;
outFile << " "<<endl;
outFile << "Rainfall of 4 or more inches occurred in April."<<endl;
outFile<<"Programmer: ";
outFile<<name;
//close the outfile
outFile.close();
return 0;
}
//define input
int readRainFall (ifstream& inFile, double rainfalls[], int MONTHS)
{
string inFileName;
int count=0;
cout << "Please enter the name of the input file: ";
cin>>inFileName;
inFile.open(inFileName);
if (!inFile.is_open())
{
cout << "Error opening file"<<endl;
}
else {
while(count<MONTHS && inFile >> rainfalls[count])
count++;
}
inFile.close();
return 0;
}
//define total
double getrainTotal (double rainfalls[], int MONTHS)
{
double total=0;
for ( int count = 0; count < MONTHS; count++)
total += rainfalls[count];
return total;
}
//define the highest rainfall
double gethighestRainfall(double rainfalls[], int MONTHS)
{
double highest;
highest = rainfalls[0];
for (int count=1; count <MONTHS; count++)
{
if (rainfalls[count] > highest)
highest = rainfalls[count];
}
return highest;
}
//define the lowest rainfall
double getlowestRainfall(double rainfalls[], int MONTHS)
{
double lowest;
lowest = rainfalls[0];
for (int count =1; count <MONTHS; count++)
{
if (rainfalls[count]< lowest)
lowest = rainfalls[count];