High low temperatures. Error on high temp?

I have two functions here. one that records the average high temperature of the year and the other one that gets the highest temperatore of the year. When im running this program I seem to get a strange number for the high temperatuere which is 23242313. What is causing this error? also I'm getting an error on line 16. Not sure that's where the error is but when I run my program it prints out high temp on screen but doesn't display anything. meanwhile that's when I get an error on my screen saying stack store_highlowtemp corrupted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//You have to store in the highest and the lowest tepmearutes in a n array. so make 12 months and two columns store[12][2]'
	unsigned int store_high_Lowtemp[months][high_Low];
	//Make a variable for high temp and low temp
	int high;
	int low;
	//call function to store in high and low temps
	getdata(store_high_Lowtemp,months);

	cout<<endl;
	//find the average high of the year
	cout<<"Average: ";
	int sum;
	sum=average_high(store_high_Lowtemp,months);
	cout<<sum;
	cout<<"\n\n\n\tHigh Temp: ";
	high_tempofyear(store_high_Lowtemp,months);
	_getch();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 //make a function to find the average high
int average_high(unsigned highlowtempstored[][high_Low], int months)
{
	int col=0;
	double hightempsum=0;
	for (int row=0;row<months;row++)
	{
		for ( col=0;col<1;col++)
		{
			highlowtempstored[row][col];
		}
		hightempsum+=highlowtempstored[row][col];
	}

	return (hightempsum/months);

}

int high_tempofyear(unsigned highlowtempstored[][high_Low],int months)
{
	int hightemp=highlowtempstored[0][0];
	int insidemax=0;
	for (int row =0;row<12;row++)
	{
		for(int col=0;col<1;col++)
		{
			insidemax=highlowtempstored[row][col];
				if (hightemp<insidemax)
					hightemp=highlowtempstored[row][col];
		}
	
	}
	return hightemp;
Last edited on
What error are you getting?
1. I don't believe that you can explicitly define lengths of input arrays in C++ the way that you did it on line 19 of the second code snippet.

2. Also, you are creating a variable sized array. I don't know if this is supported. I have always had to malloc/new to make dynamic arrays like that (line 2 in the first code snippet). Check this out:
http://www.cplusplus.com/forum/beginner/1601/
Topic archived. No new replies allowed.