1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <stdafx.h>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//*****************************************************************************
void getRainfall(float &, int);
//*****************************************************************************
int main()
{
const int SIZE = 12;
int month = 0;
float total = 0,
average,
rainfall[SIZE],
maximum = rainfall[SIZE],
minimum = rainfall[SIZE];
for(int i = 0; i < SIZE; i++)
{
getRainfall(rainfall[i], month);
total += rainfall[i];
if(rainfall[i] > maximum)
maximum = rainfall[i];
if(rainfall[i] < minimum)
minimum = rainfall[i];
month++;
}
average = total / SIZE;
cout << "" << endl;
cout << "Your total is: " << setprecision(1) << showpoint << fixed
<< setw(10) << total << endl;
cout << "Average: " << setw(15) << average << endl;
cout << "Highest: " << setw(15) << maximum << endl;
cout << "Lowest: " << setw(15) << minimum << endl;
cin.get();
cin.get();
return 0;
}
//******************************************************************************
// This function will receive the amount of rainfall from the user *
//******************************************************************************
void getRainfall (float & rain, int date)
{
const int SIZE = 12,
lowest = 0;
string months[SIZE] =
{"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"};
do
{
cout << "Please enter the rain amount for " << months[date] << ": ";
cin >> rain;
if(rain < lowest)
cout << "That isnt a vaild input!, please try again!" << endl;
}
while(rain < lowest);
}
|