Help with finding average

closed account (z8q4izwU)
Hello, Im having problems getting the right answer for finding the average high and low temperature on a project. It runs but i know the answer is wrong but cant figure out what i wrote wrong. The answer i get is the average high: 136627563.00 and the low: -23765427..... If anyone has any ideas it would help alot.

Thanks Gary

Heres the input data i have in the file....

27 38
29 42
35 50
45 61
54 71
64 79
69 84
68 83
61 75
50 64
42 54
32 32




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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<iostream>
#include<fstream>
#include<iomanip>

const int NO_OF_MONTHS = 12;
const int rows = 12;	 //make # of rows/cols a constant int
const int cols = 2;


using namespace std;

void getData( int listTemp[rows][cols]);
void averageHigh( int listTemp[rows][cols]);
void averageLow(int listTemp[rows][cols]);
void indexHighTemp(int listTemp[rows][cols]);
void indexLowTemp( int listTemp[cols][cols]);

ifstream infile;
ofstream outfile;

int main()
{
		
	
  //  ofstream outfile;
	double average;
	int listTemp[rows][cols];
	
	
	infile.open("data.txt"); //open infile
	
	   if (!infile)
    {
               cout << "Error opening data.txt " << endl;
               return 1;
    }

	
   cout<<fixed<<showpoint;   //result will be able to show decimal points
   cout<<setprecision(2);
	
	
	
	getData(listTemp);						   //call functions
	averageHigh(listTemp);
	averageLow(listTemp);
	indexHighTemp(listTemp);
	indexLowTemp(listTemp);
	
	
	  
	infile.close();

	
	system("pause");
	return 0;
	
}

	void getData(int listTemp[rows][cols])
	{													 //read data in both arrays
	
			 int x;
			 int j;
			// ifstream infile;

						 
			 
			 for (x=0; x < rows; x++)
			 {
				 for( j=0; j<cols; j++)
				 {
					  
			 infile >> listTemp[x][j] >> listTemp[x][j];
			 
		   //  outfile << listTemp[x][j] << " "<<listTemp[x][j]<< endl;
		   
					 
		   }
		   }
}
	void averageHigh ( int listTemp[rows][cols]) 
	{
			int x=1;		 
			int Sum = 0;								//read first column and find the average
			double Average;							//from the highs	   
			
			
			 for (x=0; x < rows; x++)
			 {
			 Sum = listTemp[x][0] + Sum;			
			// Average = Sum/x;			 
			 }
	   // Average = Sum/12;
		
		Average = Sum/x;
		
	   
	   
		cout << "Average high for the year: " << Average << endl<<endl;
		
		  
		}
		
	void averageLow ( int listTemp[rows][cols])
	 {
	 int Sum = 0;											//read the second column and find the
	 double Average;	   
									  //average of the lows	   
	 
			 for (int x=0; x < rows; x++)
			 {
			 Sum = listTemp [x][1] + Sum;
			 }
			 //  Average = Sum/12;
			 
			 Average = Sum/12;
	 
			 cout << "Average low for the year: " << Average << endl<<endl;
	 }
	 
	 
		
	void indexHighTemp ( int listTemp[rows][cols])
	 {
	 int highestIndex = 0;  
		
														//find highest in the "high" column					  
	 for(int x = 0; x < rows; x++)
	 {
	  if(listTemp[0][x] > highestIndex)
	  highestIndex = listTemp[0][x];
			 
	 }
	 cout << "The index high temperature is " << highestIndex <<endl<<endl;

	 }
	 
	void indexLowTemp ( int listTemp[rows][cols])
	 {
	 int lowestIndex = 0;	  
							  //find the lowest in the low column
	 
	 for(int x = 0; x < rows; x++)

	 {
		  if(lowestIndex > listTemp[0][x])
		  lowestIndex = listTemp[0][x];
			 
	 }		
	 cout << "The index low temperature is " << lowestIndex << endl<<endl;
	 }
closed account (z8q4izwU)
The low should be: 48

The high should be: 61

But my answers are no where near that.
Topic archived. No new replies allowed.