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
|
#include<iostream>
#include<math.h>
#include<conio.h>
float getMonthly(const int);
float avg_daily( int days[], float month[]);
using namespace std;
int main(){
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
int Jan_Rain=0;
int Feb_Rain=0;
int Year_Rain=0;
float month[1];
int month_number=0;
float avg_daily_rain=0;
float Jan_avg=0;
Jan_Rain = getMonthly(days[0]);
cout<<"The monthly rainfall for January is ";
cout<<Jan_Rain<<endl;
month[0]=Jan_Rain;
Feb_Rain = getMonthly(days[1]);
cout<<"The monthly rainfall for February is ";
cout<<Feb_Rain<<endl;
month[1]=Feb_Rain;
cout<<"The total rainfall for the year is ";
cout<<Year_Rain<<endl;
for
(month_number=0; month_number<=1; month_number++)
{
Year_Rain+=month[month_number];
}
cout<<Year_Rain<< endl;
Jan_avg= avg_daily(days[0],month[0]);
cout<<"The average daily rainfall for january is";
cout<<Jan_avg<<endl;
return 0;
getch();
}
float getMonthly( const int days )
{
float rain_total = 0.0f;
int day = 0;
for ( int day = 0; day < days; ++day )
{
cout << "\nPlease enter the rainfall for day " << 1+day << ": ";
float rainfall = 0.0f;
cin >> rainfall;
rain_total += rainfall;
}
return rain_total;
}
float avg_daily( int days[], float month[])
{
float avg=0.0f;
int number=0;
for(int number=0; number<=11; ++number){
avg= month[number]/days[number];
}
cout<<" The average is";
cout<<avg<<endl;
}
|