//Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year.
//The program should output the average high, average low, and the highest and lowest temperatures for the year.
#include <iostream>
using namespace std;
const int months = 12;
void input( double A[][2], int B);
double averageHigh(double A[][2], int B);
double averageLow(double A[][2], int B);
int indexHigh(double A[][2], int B);
int indexLow( double A[][2], int B);
int main()
{
double temperatures [months][2];
input(temperatures, months);
// getting the information, input.
cout << "Average high temperature for the year is "
<< averageHigh(temperatures, months)<<endl;
cout << "Average low temperature for the year is "
<< averageLow(temperatures, months)<<endl;
// output.
cout << "Highest temperature for the year is "
<< indexHigh(temperatures, months)<<endl;
cout << "Lowest temperature for the year is "
<< indexLow(temperatures, months)<<endl;
return 0;
}
void input(double A[][2], int B)
{
for (int i = 0; i < B; i++)
{
cout << "Enter the highest temperature for the month:"
<< (i+1) ;
cin >> A[i][1];
cout << "Enter the lowest temperature for the month:"
<< (i+1) ;
cin >> A[i][0];
}
}
double averageHigh(double A[][2], int B)
{
double sum = 0;
for (int i = 0; i <B; i++)
sum +=A[i][0];
return (sum/B);
}
double averageLow(double A[][2], int B)
{
double sum = 0;
for( int i = 0; i < B; i++)
sum +=A[i][1];
return (sum/B);
}
int indexHigh(double A[][2], int B)
{
int index = 0;
double highest = A[0][0];
for(int i =1; i <B; i++)
if (A[i][0] > highest)
{
highest = A[i][0];
index =i;
}
return index;
}
int indexLow(double A[][2], int B)
{
int index = 0;
double lowest = A[0][1];
for (int i = 1; i < B; i++)
if (A[i][1] < lowest)
{
lowest = A[i][1];
index = i;
}