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
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void avgRainfall (string a[], int numMonths, double &avgTotal);
void actRainfall (string a[], int numMonths, double &totalRain);
void diffRain ( double &totalRain , double &avgTotal );
int main()
{
const int Months = 12;
string names[Months]={"January", "February", "March", "April", "May", "June", "July", "August", "September"
, "October", "November", "December"};
double totalRain, avgTotal;
avgRainfall(names, Months, avgTotal);
cout << endl;
actRainfall(names, Months, totalRain);
diffRain (totalRain , avgTotal );
return 0;
}
// first function will get the info for the average rainfall
// this program will take in array name and number
// this will reference avgtotal to keep the value in main
void avgRainfall (string a[], int numMonths, double &avgTotal)
{
double avgRain [12];
avgTotal = 0;
for (int i= 0; i < numMonths; i++ )
{
cout << "Please enter last years average rainfall "
<< "in inches for " << a[i] << endl;
cin >> avgRain [i];
avgTotal += avgRain [i];
}
//cout << "Your total average rainfall is " << avgTotal << endl;
}
// this function will get the actual rainfall
// will take in names and months
// this will reference total rain to keep the value accessible in main
void actRainfall (string a[], int numMonths, double &totalRain)
{
double actRain [12];
totalRain = 0;
for ( int i = 0; i < numMonths; i++)
{
cout << "Please enter the actual rainfall "
<< "in inches for " << a[i] << endl;
cin >> actRain [i];
totalRain += actRain [i];
}
//cout << " you total actual rainfall is " << totalRain << endl;
}
// function will show the difference between the average
// and the actual rainfall
void diffRain ( double &totalRain , double &avgTotal )
{
cout << "Your total rain fall for the year is: " << totalRain << "inches" << endl;
cout << "Compared to the average rainfall of last year: " << avgTotal << "inches" << endl;
double sumTotal;
sumTotal = (totalRain - avgTotal);
cout << "The difference in the rainfall between last year and this year is: " << sumTotal << "inches";
}
|