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
|
//This program takes a years worth of rainfall and displays the month with lowest and highest rainfall.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
double avgRain = 0;
double rainSum = 0;
int count = 0;
double monthlyTotals[12];
double lowpoint=100000000;
double highpoint=0;
string lowMonth;
string highMonth="January";
string monthNames[] = {"January","Febuary","March","April","May","June","July","August","September","October","November","December"};
void totalRainfall(int);
void averageRainfall(int);
void driestmonth(int);
void wettestMonth(int);
int main ()
{
//Takes numbers for months.
cout << "Enter the amount of rainfall for each month. " << endl;
for (count = 0; count <= 11; count++)
{
cout << monthNames[count] << " : ";
cin >> monthlyTotals[count];
while (monthlyTotals[count] < 0)
{
cout << "Please reenter a positive number for the month of " << monthNames[count] << endl;
cin >> monthlyTotals[count];
}
}
void totalRainfall();
void averageRainfall();
void driestmonth();
void wettestMonth();
//Displays Report
cout<<"\n 2012 Rain Report for Neversnows County"<<endl<<endl;
cout<<"Total rainfall "<<rainSum<<" incehs."<<endl;
cout<<"Average monthly rainfall "<<avgRain<<" inches."<<endl;
cout << "The least rain fell in ";
for (count=0; count <=11; count++)
if (monthlyTotals[count] == lowpoint)
cout << monthNames[count] << ", ";
cout << "with "<< lowpoint << " inches." << endl;
cout << "The most rain fell in ";
for (count=0; count <=11; count++)
if (monthlyTotals[count] == highpoint)
cout << monthNames[count] << ", ";
cout << " with "<< highpoint <<" inches." << endl;
return 0;
}
void totalRainfall(double rainSum){
// Calculates rain average
for (count =0; count <=11; count++)
rainSum = rainSum + monthlyTotals[count];
}
void averageRainfall(double avgRain){
avgRain = rainSum / 12;
}
void driestmonth(double highpoint){
// Calculates rain month highest month
highpoint = monthlyTotals[0];
for (count=0; count<=11; count++)
{
if (monthlyTotals[count] >= highpoint)
{
highpoint = monthlyTotals[count];
highMonth = monthNames[count];
}}
}
void wettestMonth(double lowpoint){
// Calculates rain moth lowest month
lowpoint = monthlyTotals[0];
for (count=0; count<=11; count++)
{
if (monthlyTotals[count] <= lowpoint)
{
lowpoint = monthlyTotals[count];
lowMonth = monthNames[count];
}
}
}
|