Hey guys, how can I find the lowest and highest number for the rainfall? I tried some things that lead to nowhere. Normally I can solve a problem like this because I don't have a limitation of the number input being 0 or more (such as this program). How can I make this work properly?
#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
double total = 0;
double Greatest = 0;
string greatest;
string least;
double Least = 0;
constint months = 12;
double rainfall[months];
string Months[months] = {"January", "February", "March", "April", "May", "June", "July"
, "August", "September", "October", "November", "December"};
cout << "In this program you will be entering data for each month (in inches)." << endl;
cout << "Please enter the data..." << endl;
for (int x = 0; x < months; x++)
{
cout << "Enter rainfall (inches) for " << Months[x] << ": ";
cin >> rainfall[x];
while (rainfall[x] < 0)
{
cout << "Invalid. Rainfall must be 0 inches or more." << endl;
cin.clear();
cin.ignore();
cin >> rainfall[x];
}
if (rainfall[x] > 0)
{
Greatest = rainfall[x];
greatest = Months[x];
}
elseif (rainfall[x] < 0)
{
Least = rainfall[x];
least = Months[x];
}
total += rainfall[x];
}
double average;
average = total/months;
cout << "\nThe total rainfall for the year was " << total << " inches." << endl;
cout <<"The monthly average for the year was " << average << " inches." << endl;
cout <<"\nThe month with the most rainfall was " << greatest << " with " << Greatest << " inches." << endl;
cout <<"The month with the least rainfall was " << least << " with " << Least << " inches." << endl;
system("pause");
return 0;
}