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
|
#include <iostream>
#include <string>
using namespace std;
const int days = 3;
const int months = 3;
const int extremes = 2;
double average_temp(int[days][months], int);
int main()
{
int almanac[days][months][extremes] =
{
{{67,50}, {71,53}, {75,55}}, // day 1
{{67,50}, {72,53}, {75,55}}, // day 2
{{67,50}, {72,53}, {75,55}}, // day 3
};
string userchoice;
cout << " I have a bunch of weather data. There are a few ways this data can be displayed. " << endl;
cout << " Enter 1 - the high temperatures for all the data. " << endl;
cout << " Enter 2 - the low temperatures for all the data. " << endl;
cout << " Enter 3 - the average temp for June, July or August. " << endl;
cout << " Enter 4 - the highest temp for June, July or August. " << endl;
cout << " Enter 5 - the lowest temp for June, July or August. " << endl;
cin >> userchoice;
if(userchoice == "3")
{
cout << "\nThe average tempearature was" << average_temp(almanac, [days][months]) << endl; // This is where error is showing.
}
return 0;
}
double average_temp(int A[3][3], int num_elements)
{
int total=0;
double avg;
for (int i = 0; i < num_elements; i++)
{
for (int j = 0; j < num_elements; j++)
{
total = total + A[i][j];
}
}
avg = (double) total / (double) num_elements;
return avg;
}
|