Okay, found out how to get the months to display when entering the rainfall but I cant figure out how to get it to display the name of the month for the lowest and highest rainfall( Lines 51 and 66). The way I have it when I enter the last rainfall it displays the total and average then beeps and shows weird characters for the highest and lowest.
Code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
double total;
int main()
{
const int array_size = 12;
string name[array_size] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
double rain[array_size];
int count;
double average;
double lowest;
double highest;
cout << "Please enter the rainfall for all 12 months" << endl;
cout << "After each input please press enter to input the next number" << endl << endl;
for (count = 0; count < array_size; count++)
{
cout << "Please enter " << name[count] << " rainfall: ";
cin >> rain[count];
if (rain[count] < 0)
{
cout << "Rainfall can not be a negative number" << endl;
cout << "Please re-enter " << name[count] << " rainfall: ";
cin >> rain[count];
}
total += rain[count];
}
average = total/12;
cout << "The total rainfall for the year is: " << total << endl;
cout << "The average rainfall for the year is: " << average << endl;
highest = rain[0];
for (count = 1; count < array_size; count++)
{
if (rain[count] > highest)
{
highest = rain[count];
}
}
cout << "The highest rainfall is in " << name[count] << " with: " << highest << " inches" << endl;
lowest = rain[0];
for (count = 1; count < array_size; count++)
{
if (rain[count] < lowest)
{
lowest = rain[count];
}
}
cout << "The lowest rainfall is in " << name[count] << " with: " << lowest << " inches" << endl;
return 0;
}