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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
//Global V&C
const int SIZE= 12;
void welcome();
void getData (double [], int qty);
double totalRainfall(double [], int qty);
double averageRainfall(double [], int qty);
void wettestMonth(double [], int &wM, double &highest);
void driestMonth(double [], int &dM, double &lowest);
int main()
{
//V&C
double rainfall[SIZE];
double tRF = 0, aRF = 0, lowest, highest;
int wM = 0 , dM = 0;
string month[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
welcome();
//Input
getData(rainfall, SIZE);
tRF = totalRainfall(rainfall, SIZE);
// aRF = averageRainfall(rainfall, SIZE);
wettestMonth(rainfall, wM, highest);
driestMonth(rainfall, dM, lowest);
//Output
cout<<fixed<<setprecision(2);
cout<<endl<<"The Rain Report for Neversnows County"<<endl;
cout<<"-------------------------------------"<<endl;
cout<<"Total rainfall for the year: "<<tRF<<" inches"<<endl;
cout<<"Average rainfall for the year: "<<aRF<<" inches"<<endl;
cout<<"The least amount of rain fell in "<<month[dM]<<" with "<<lowest<<" inches"<<endl;
cout<<"The most amount of rain fell in "<<month[wM]<<" with "<<highest<<" inches"<<endl;
cout<<"-------------------------------------"<<endl;
return 0;
}
void welcome ()
{
cout << "Welcome to the Rainfall Statistics Program "<<endl;
return;
}
void getData (double rainfall [], int SIZE)
{
int count;
cout<< "Please enter the amount of inches of rainfall for the year.\n(Please hit the Return key after each input)"<<endl;
for (count = 0; count < SIZE; count++)
{
cin>> rainfall[count];
//Validation
if (rainfall[count] < 0)
{
cout << "Please only use positive numbers." << endl;
cin>> rainfall[count];
}
}
}
double totalRainfall(double rainfall [], int SIZE)
{
int count;
double tRF = 0;
for (count = 0; count < SIZE; count++)
{
tRF += rainfall[count];
}
return tRF;
}
double averageRainfall(double tRF, int SIZE)
{
double aRF = 0;
aRF = tRF/SIZE;
return aRF;
}
void driestMonth(double rainfall [], int &dM, double &lowest)
{
lowest = rainfall[0];
for (int count = 1; count < SIZE; count++)
{
if (rainfall[count] < lowest)
{
lowest = rainfall[count];
dM++;
}
}
}
void wettestMonth(double rainfall [], int &wM, double &highest)
{
highest = rainfall[0];
for (int count = 1; count < SIZE; count++)
{
if (rainfall[count] > highest)
{
highest = rainfall[count];
wM ++;
}
}
}
|