I'm not sure what I'm doing wrong so if you could take a look and give me some ideals it would be great. Thanks so much
Specifications: Write a program that uses a two-dimensional array to store the highest and lowest temperature for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures, along with the corresponding month.
Data:
42.6 23.7
44.9 25.2
52.0 30.9
61.6 39.1
69.4 47.5
75.7 55.1
78.2 58.9
77.5 57.7
72.0 51.6
63.4 40.8
53.0 32.1
44.9 25.7
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
const int numRows = 12;
const int numCols = 2;
void getData(ifstream& inputFile, double temps[][numCols], int numRows);
void averageHigh(double temps[][numCols], int numRows);
void averageLow(double temps[][numCols], int numRows);
void indexHighTemp(double temps[][numCols], int numRows);
void indexLowTemp(double temps[][numCols], int numRows);
int main()
{
double temps[numRows][numCols] = {0.0};
fstream infile;
infile.open("Weather.txt");
if (!infile)
{
cout << "Cannot open the input file. Program terminates!"
<< endl;
return 1;
}
while (infile)
{
getData(infile, temps, numRows);
averageHigh(temps, numRows);
averageLow(temps, numRows);
indexHighTemp(temps, numRows);
indexLowTemp(temps, numRows);
cout << endl;
}
infile.close();
return 0;
}
void getData(ifstream& inputFile, double temps[][numCols], int numRows)
{
cout << fixed << showpoint << setprecision(1);
double hiTemp, loTemp;
string month;
inputFile >> hiTemp >> loTemp;
int rowIndex = 0;
int colIndex;
while (inputFile)
{
temps[rowIndex][0] = hiTemp;
temps[rowIndex][1] = loTemp;
rowIndex++;
inputFile >> hiTemp >> loTemp;
}
}
void averageHigh(double temps[][numCols], int numRows)
{
double sum = 0;
double avgHigh =0;
for (int i=0; i<numRows; i++)
sum += temps[i][0];
avgHigh = (sum/numRows);
cout<< "Average High was: "<< avgHigh << endl;
}
void averageLow(double temps[][numCols], int numRows)
{
double sum = 0;
double avgLow = 0;
for (int i=0; i<numRows; i++)
sum += temps[i][1];
avgLow = (sum/numRows);
cout << "Average Low was: "<< avgLow << endl;
}
void indexHighTemp(double temps[][numCols], int numRows)
{
int ind = 0;
double highest = temps[0][0];
for (int i=1; i<numRows; i++)
if (temps[i][0] > highest)
{
highest = temps[i][0];
ind = i;
}
cout << "Highest temp of year was: " << ind << endl;
}
void indexLowTemp(double temps[][numCols], int numRows)
{
int ind = 0;
double lowest = temps[0][1];
for (int i=1; i<numRows; i++)
if (temps[i][1] < lowest)
{
lowest = temps[i][1];
ind = i;
}
cout<< "Lowest temp of the year was: " << ind << endl;
}