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
|
#include <iostream>
#include <conio.h>
using namespace std;
void enter_rainfalls(double rainfalls[][12])
{
for(int x=0; x<3; x++)
{
for(int y=0; y<12; y++)
{
cout<<"Please enter rainfall"<<endl;
cin>>rainfalls[x][y];
}
}
}
void print_rainfalls(double rainfalls[][12])
{
cout<<"\nPrinting rainfalls...\n"<<endl;
for(int x=0; x<3; x++)
{
for(int y=0; y<12; y++)
{
cout<<rainfalls[x][y]<<" ";
;
}cout<<endl;
}
}
double avg_rainfall(double rainfalls[][12])
{
double sum=0.0;
double avg=0.0;
for(int x=0; x<3; x++)
{
for(int y=0; y<12; y++)
{
sum += rainfalls[x][y];
}
}
avg = sum / 36;
cout<<"\nThe average rainfall of the last three years = "<<avg;
return avg;
}
int main(void)
{
double rainfalls[3][12] = {{10.3, 12.4, 12.0, 15.5, 13.5, 12.6, 10.7, 8.6, 9.2, 8.0, 9.0, 10.0},
{9.3, 10.4, 8.0, 15.5, 11.5, 13.6, 11.7, 9.6, 9.6, 9.0, 11.0, 12.0 },
{10.5, 13.4, 10.0, 13.5, 12.5, 14.6, 9.7, 10.0, 10.2, 7.0, 10.0, 11.0}} ;
enter_rainfalls(rainfalls);
print_rainfalls(rainfalls);
avg_rainfall(rainfalls);
getch();
}
|