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.

Line 35 - what's 'i' doing there?

I take it your loop at lines 34,35 should be displaying just the high temps and you will write a similar loop for the low temps? So, how are you pointing to the correct row of temp data?

Line 35 - what's 'i' doing there?

I take it your loop at lines 34,35 should be displaying just the high temps and you will write a similar loop for the low temps? So, how are you pointing to the correct row of temp data?

Oh wow, I see what you mean, I must have passed right over that. I had it in another loop that was dealing with 'i' and forgot to change it. Everything is printing out just fine now.

Small bugs like that always kill me haha.

Thanks.

It's the little ones that will drive you nuts.

And it's hard to spot them yourself, as you're so invested in the what you wrote. Just like proofreading your own documents.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.