Here\'s the code given to go off of: /*analysis.cpp*/ #include <iostream> #inclu
ID: 3588130 • Letter: H
Question
Here's the code given to go off of:
/*analysis.cpp*/
#include <iostream>
#include <string>
using namespace std;
//
// InputYearOfDataAndReturnAverage()
//
// Inputs 12 rainfall values --- one per month --- and returns the average.
//
double InputYearOfDataAndReturnAverage()
{
//
// TODO:
//
return -1.0;
}
Explanation / Answer
The below prpgram results the same as reuired. the main program is calling function InputYearOfDataAndReturnAverage and passing 12 months data into it and the function returns the avergae of data. the programs terminates when we pass -1 to it.
/*analysis.cpp*/
#include <iostream>
#include <string>
using namespace std;
//
// InputYearOfDataAndReturnAverage()
//
// Inputs 12 rainfall values --- one per month --- and returns the average.
//
double InputYearOfDataAndReturnAverage(double monthData[13]){
int i;
double avg = 0.0;
for(i=0;i<12;i++){
avg += monthData[i];
}
avg = avg/12.0;
return avg;
}
int main(){
int year,i;
double monthData[13],avg;
while(1){
cin>>year;
if(year == -1) break;
for(i=0;i<12;i++){
cin>>monthData[i];
}
avg = InputYearOfDataAndReturnAverage(monthData);
cout<<year<<": "<<avg<<" ";
}
return 0;
}