Can someone ,please help me to fix the error on these Functions



Write a program that uses a two-dimensional array to store the highest and lowest temperatures
for each month of the year. The program should output the average high, average low, and the
highest and lowest temperatures for the year. Your program must consist of the following
functions:
a. Function This function reads and stores data in the two dimensional array.
b. Function : This function calculates and returns the average high
temperature for the year.
c. Function This function calculates and returns the average low temperature
for the year.
d. Function This function returns the index of the highest high
temperature in the array.
e. Function This function returns the index of the lowest low
temperature in the array.
(These functions must all have the appropriate parameters.)


when I run the code it comes out:

sum + = t [ i ] [ 1 ];
^

error: expected expression
<< ( i + ! ) << " : ";

error: expected expression
sum + = t [ i ] [ 0 ]

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
   //header 
   #include <iostream>
   using namespace std;

   const int MONTHS = 12;

   //prototypes of the functions:
   void getData( double [][ 2 ], int );
   double averageHigh ( double [] [ 2 ],int );
   double averageLow ( double [] [ 2 ], int );
   int indexHighTemp ( double [] [ 2 ], int );
   int indexLowTemp ( double [] [ 2], int );

   //Function main

   int main()
   {
	   // Declare the variables
	   double temperatures [ MONTHS ] [ 2 ];

	   // Get data from user
	   getData( temperatures, MONTHS );

	   //Print the results to the user
	   cout << "\n\n\t The average high temperature for the year is "
			<< averageHigh ( temperatures, MONTHS);
	   cout << "\n\n\t The average low temperature for the year is "
			<< averageLow ( temperatures, MONTHS);
	   
	   // Print the results to the user
	   cout <<"\n\n\t Index of highest temperature for the year is "
			<< indexHighTemp (temperatures, MONTHS );
	   cout << "\n\n\t Index of lowest temperature for the year is "
			<< indexLowTemp ( temperatures, MONTHS );

	return 0;

   }

   //REads and stores data in the array

   void getData ( double t [] [ 2 ], int m)
   {
		 for ( int i = 0; i < m; i ++ )
		 { 
		 // Prompt and read the input from the user
			 cout << "\n\t Enter highest temperature for the month"
				  << ( i + 1 ) << " : ";
			 cin >> t [ i ] [ 0 ];
			 
			 //Prompt and read the input from the user
			 cout << "\t Enter lowest temperature for the month "
				  << ( i + 1 ) << " : ";
			 cin >> t [ i ] [ 1 ];
		  }
   }
// Returns the average high temperature of the ywear
double averageHigh ( double t [] [ 2 ], int m)
{
	//Decalre a variable
	double sum = 0;

	// Compute the sum of the highest temperatures
	for ( int i = 0 ; i < m; i ++)
		sum + = t [ i ] [ 0 ];
	
	//return average of the Highest temperatures
	return ( sum/m);
}
//Returns the average Low Tempereature of the year

double averageLow( double t [] [ 2 ], int m)
{
	//Declare a variable
	double sum =0;

	//Compute the sukm of the lowest temperatures
	for ( int i = 0; i < m; i ++)
		sum + = t [ i ] [ 1 ];
	
	//Return the average of the Lowest temperatures
	return ( sum / m);
}

//Returns the index of highest of high temperatures
int indexHighTemp (double t [] [ 2 ], int m )
{
	//Declare the variables
	int ind = 0;
	double highest = t [ 0 ] [ 0 ];

	//Search for the highest high temperature
	for ( int i= 1; i < m ; i ++)
		if ( t [ i ] [ 0 ] > highest )
		{
			//Modify the highest and index
			highest = t [ i ] [ 0 ];
			ind = i;
		}
//Return the index of highest high temperature
return ind;
//End of the Function indexHighTemp
}

//Returns the index of lowest of low temperatures

int indexLowTemp ( double t [] [ 2 ], int m)
{
	//Declare the variable
	int ind = 0;
	double lowest = t [ 0 ] [ 1 ];

	//Search for the lowest low temperature
	for (int i = 1; i < m; i ++)
		if( t [ i ] [ 1 ] < lowest )
		{
			 //Modify the lowest and index
			 lowest = t [ i ] [ 1 ];
			 ind = i;
		}
	
	//Return the index of the low temperature
	return ind;
//End of function indexLowTemp
}	
Remove the white-space between '+' and '='. The add-assignment operator has no spaces in the name.
Last edited on
Topic archived. No new replies allowed.