Is my functions correct? If I type in the highest temp at the bottom row, my program wouldn't take it. Same goes for lowest temp.
Can anyone provide some in sight?
#include <iostream>
using namespace std;
//declare constant for array temperature
int const row = 3;
int const col = 2;
double temp[row][col];
//function prototypes
void getData(double temp[row][col]);
void avghigh(double temp[row][col]);
void avglow(double temp[row][col]);
void hitemp(double temp[row][col]);
void lotemp(double temp[row][col]);
int HIGH = 0;
int LOW = 1;
//main function
int main()
{
double temp[row][col];
//calling function for data input
getData(temp);
//calling the functions to display average and hi/lo temp.
avghigh(temp);
avglow(temp);
hitemp(temp);
lotemp(temp);
system("pause");
return 0;
}
//all functions definetion
void getData(double temp[row][col])
{
int i;
cout << "Enter high temperature." << endl; //user inputs for each month. highest temperature in first row
for (i=0 ; i<row; i++)
{
cout << "Month: " << (i+1) << " ";
cin >> temp[i][HIGH];
}
cout << "Enter low temperature." << endl; //user inputs for each month. lowest temp in first row
for (i=0 ; i<row; i++)
{
cout << "Month: " << (i+1) << " ";
cin >> temp[i][LOW];
}
}
void avghigh(double temp[row][col])
{
int i;
int Sum = 0;
double Average;
for (i=0; i<row; i++)
{
Sum = temp[i][0] + Sum;
}
Average = Sum/i;
cout << "Average high temperature for the whole year is: " << Average << endl;
}
void avglow(double temp[row][col])
{
int Sum = 0;
int i;
double Average;
for (i=0; i<row; i++)
{
Sum = temp [i][1] + Sum;
}
Average = Sum/i;
cout << "Average low temperature for the whole year is: " << Average << endl;
}
void hitemp(double temp[row][col])
{
int highesttemp = 0;
int i;
for(i=0; i<row; i++)
{
if(temp[0][i] > highesttemp)
highesttemp = temp[0][i];
}
cout << "The highest temperature is: " << highesttemp << endl;
}
void lotemp(double temp[row][col])
{
int lowesttemp = 0;
int i;
for(i=0; i<row; i++)
{
if(temp[0][i] < lowesttemp)
lowesttemp = temp[0][i];
}
cout << "The lowest temperature is: " << lowesttemp << endl;
}