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 <cstdlib>
#include <iostream>
const int SIZE = 3;
void getTemps(float temp[],int SIZE);
float calcAvg(float temp[],int SIZE, float sum);
void displayAvg(float temp[],int SIZE, float average);
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
float temp[SIZE];
float average =0;
getTemps( temp,SIZE);
average = calcAvg(temp,SIZE, average);
displayAvg(temp,SIZE,average);
return 0;
}
void getTemps(float *temp,int SIZE) ////////////////////////////////////////////////////////////////////
{
cout << "enter the temperatures for each of the three cities"<< endl;
for (int i = 0; i < SIZE; i ++) //////////////////////////////////////////////////////////////////
{
cin >> temp[i];
}
}
float calcAvg(float *temp,int SIZE, float average) ///////////////////////////////////////////////////
{
//float average; /////////////////////////////////////////////////////////////////////////////////
for ( int i = 0; i < SIZE; i++)
{
average += temp[i];
}
return average;
}
void displayAvg(float *temp,int SIZE, float average) //////////////////////////////////////////////////
{
cout << "here are the temperatures"<< endl;
for (int i= 0; i < SIZE; i++) ////////////////////////////////////////////////////////////////////
{
cout << temp[i] << endl;
}
cout << "here is the average "<<average/SIZE<< endl; ///////////////////////////////////////////////
}
| |