I'm trying to create a program where it reads in the high and low temperatures for each month of the year using a 2D array. However, I cannot seem to get it working correctly. It outputs a bunch of strange numbers.
#include <iostream>
#include <iomanip>
using namespace std;
const int MONTHS = 12;
void getData(double [][2], int);
int main()
{
double temperatures[MONTHS][2];
getData(temperatures, MONTHS);
return 0;
}
void getData(double t[][2], int m)
{
int i, j, k;
for(i=0; i < m; i++)
{
cout << "Enter higest temperature for the month " << i+1 << ": ";
cin >> t[i][0];
cout << "Enter lowest temperature for the month " << i+1 << ": ";
cin >> t[i][1];
}
cout << "Jan" << setw(5) << "Feb" << setw(5) << "Mar" << setw(5) << "Apr" << setw(5) << "May" << setw(5) << "Jun" << setw(5);
cout << "Jul" << setw(5) << "Aug" << setw(5) << "Sep" << setw(5) << "Oct" << setw(5) << "Nov" << setw(5) << "Dec" << setw(5) << endl;
for(j=0; j<m; j++)
cout << t[i][0] << setw(5);
}
Here is what the output is suppose to look like:
Month: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
High: 43 45 51 57 64 70 75 75 69 59 49 45
Low: 34 34 38 42 49 54 58 57 52 46 39 36
And here's what my output currently looks like.
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2.64212e-3082.64212e-3082.64212e-3082.64212e-3082.64212e-3082.64212e-3082.64212e
-3082.64212e-3082.64212e-3082.64212e-3082.64212e-3082.64212e-308
And help would be appreciated. Thanks in advance.