is this correct?
Code:
#include <iostream>
#include <conio.h>
using namespace std;
//the function prototypes
void getData(int array[][2]);
double averageHigh(int array[][2]);
double averageLow(int array[][2]);
int indexHighTemp(int array[][2]);
int indexLowTemp(int array[][2]);
int main()
{
int months[12][2];
getData(months);
//telling the user the average high temperature
cout << "Average high temperature:"
<< averageHigh(months) << endl;
//telling the user the average low temperature
cout << "Average low temperature:"
<< averageLow(months) << endl;
//telling the user the highest temperature
cout << "Highest temperature:"
<< indexHighTemp(months) << endl;
//telling the user the lowest temperature
cout << "Lowest temperature:"
<< indexLowTemp(months) << endl;
getch ();
return 0;
}
void getData(int array[][2])
{
/* asks the user to input the highest and lowest temperatures
and contains the for loop to store it and a counter.*/
cout << "Please enter highest temperatures for each month." << endl;
for(int i=0; i<12; i++)
cin >> array[i][0];
cout << "Please enter lowest temperatures for each month." << endl;
for(int i=0; i<12; i++)
cin >> array[i][1];
}
//does the math for the average high temperatures
double averageHigh(int array[][2])
{
int sumHigh = 0;
for(int i=0; i<12; i++)
sumHigh += array[i][0];
return sumHigh/12.0;
}
//does the math for the average low temperatures, also contains a for looop
double averageLow(int array[][2])
{
int sumLow = 0;
for(int i=0; i<12; i++)
sumLow += array[i][1];
return sumLow/12.0;
}
//a nested for loop to find the highest and lowest temperature
int indexHighTemp(int array[][2])
{
int highTemp = 0;
for(int i=0; i<12; i++)
{
if(array[i][0] > highTemp)
{
highTemp = array[i][0];
}
}
getch();
return highTemp;
}
int indexLowTemp(int array[][2])
{
int lowTemp = array[0][1];
for(int i=1; i<12; i++)
{
if(array[i][1] < lowTemp)
{
lowTemp = array[i][1];
}
}
getch();
return lowTemp;
}