many errrors for source code and progamming help!

Hi, i m having many errors on my work and needs to fix the code below
I need to calculate and output the result of the hourly temperatures for each hour of the day (i.e., 24 temperatures) and use array in this context.

I m having over 30 errors and some of errors are;

header file
Error 1 error C2065: 'array' : undeclared identifier
Error 2 error C2062: type 'int' unexpected


test.cpp
Error 11 error C2065: 'NUM_TEMPERATURES'
Error 12 error C2975: '_Size' : invalid template argument for 'std::array', expected compile-time constant expression



//header file//

#ifndef weather_h // Avoid duplicate compilations
#define weather_h
void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures);
int ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
void DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
int Low(array<int, NUM_TEMPERATURES>& Tempeartures);
int High(array<int, NUM_TEMPERATURES>& Temperatures);
#endif



//main file//
#include<iostream> // for cin,cout
#include<limits> // Required for numeric_limits
#include<array>
#include<ctime>
#include"test.cpp"
#include"weather.h"
using namespace std;


int main()
{
// declare local constant(s), variable(s), and array(s)

array<int, 24> HourlyTemperatures;
const int NUM_TEMPERATURES = 24;
int Temperatures[NUM_TEMPERATURES];
int AverageTemp = 0;
char run;
cout << endl;
cout << "Press 'A' continue - Press 0 to quit.";
cin >> run;
do
{
GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures);
Sleep(1500);
AverageTemp = ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Temperatures); //take the last parameter out of the ComputeAverageTemp function
Sleep(1500);
int lowTemp = Low(array<int, NUM_TEMPERATURES>& Temperatures);
Sleep(1500);
int highTemp = High(array<int, NUM_TEMPERATURES>& Temperatures);
Sleep(1500);
DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, AverageTemp, lowTemp, highTemp); //update your header prototype for DisplayTemperatures
Sleep(3500);


} while (run == 0);
cout << " Okay - Another Time ";
return 0;
}


//test.cpp//

#include<iostream> // for cin,cout
#include<iomanip> // for formatting cout
#include<array>
#include"weather.h" // for linking to main cpp file
using namespace std;

void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures)
{
int CurrentTemp = 0;
for (int i = 0; i < NUM_TEMPERATURES; i++)
{
cout << "Input hourly temp: ";
cin >> Temperatures[i];
while ((Temperatures[i] >130) || (Temperatures[i]< -50))
{
cout << "Out of range - Try Again";
--i;
}
}
}
// takes the values in the array and returns high, low, and mean
int ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
{
//average the values in the array
int sum = 0;
for (int i = 0; i < NUM_TEMPERATURES; i++)
{
sum += Temperatures[i];
}
AverageTemp = sum / NUM_TEMPERATURES;
return AverageTemp;
}
int High(array<int, NUM_TEMPERATURES>& Temperatures);
{
//find the highest value in the array
int highValue = Temperatures[0];
for (int i = 0; i<NUM_TEMPERATURES; i++)
{
if (Temperatures[i] > highValue)
{
highValue = Temperatures[i];
}
}
return highValue;
}
int Low(array<int, NUM_TEMPERATURES>& Temperatures);
{
//find the lowest value in the array
int lowValue = Temperatures[0];
for (int i = 0; i < NUM_TEMPERATURES; i++)
{
if (Temperatures[i] < lowValue)
{
lowValue = Temperatures[i];
}
}
return lowValue;
}
// displays the full run of values, the high, low, and mean
void DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
{
cout << fixed << setprecision(2);
cout << "Hour" << setw(9) << " Temperature\n";
for (int x = 0; x<10; ++x)
{
cout << setw(2) << "0" << x << ":00" << setw(7) << Temperatures[x] << endl;
}
for (x = 10; x<NUM_TEMPERATURES; ++x)
{
cout << setw(3) << x << ":00" << setw(7) << Temperatures[x] << endl;
}
Sleep(1500);
cout << setw(8) << "High" << setw(9) << highTemp << endl;
cout << setw(8) << "Low" << setw(9) << lowTemp << endl;
cout << setw(8) << "Average" << setw(9) << AverageTemp << endl;
return;
}











In your header file, you are missing the scope qualifier std:: in front of array.

In your main file, you are not calling the functions correctly.
AverageTemp = ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Temperatures); should be AverageTemp = ComputeAverageTemp(Temperatures);

I'm not sure if you have any more errors, but if there are I'm sure others can point them out. You should really post your code inside the code tags. [ code ] [ /code ] without the spaces.
you also #include"test.cpp"

this should be compiled separately and then linked.
Hello
In you code i found that the function
void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures); has problem

You replace it
1
2
#define NUM_TEMPERATURES 24
void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures);


You try to compiler is not able to recognize NUM_TEMPERATURES value try to modify all your function.By this you can reduce numbers of error
Thank you for the number of response.

I revised the header file based on the recommendation.




//header file//
#ifndef weather_h // Avoid duplicate compilations
#define weather_h
#include"test.cpp"
#define NUM_TEMPERATURES 24
void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures);
int ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
void DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
int Low(array<int, NUM_TEMPERATURES>& Tempeartures);
int High(array<int, NUM_TEMPERATURES>& Temperatures);
#endif


Your header file should look like this:

1
2
3
4
5
6
7
8
9
10
11
//header file//
#ifndef weather_h // Avoid duplicate compilations
#define weather_h
#include <array>
#define NUM_TEMPERATURES 24
void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures);
int ComputeAverageTemp(std::array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
void DisplayTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
int Low(std::array<int, NUM_TEMPERATURES>& Tempeartures);
int High(std::array<int, NUM_TEMPERATURES>& Temperatures);
#endif 
Thank you fg109.
Once I input the way you wrote, there is no error for header file.
I still get about 30 errors from main and test.cpp.

In test cpp, do I needto change void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures) to void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures); ?
If so, do I also need to make the change for int ComputeAverageTemp, void DisplayTemperatures, int Low, int High too?

Thanks

In your test.cpp, you have using namespace std; so you don't need to put std:: in front of array. You should post your errors, and put your source code inside the code brackets.
Error I m having right now is


//Test.cpp//
Error 1 error C2447: '{' : missing function header (old-style formal list?)
Warning 5 warning C4091: '' : ignored on left of 'const int' when no variable is declared
23 IntelliSense: expected a declaration

//main.cpp//
Error 6 error C2143: syntax error : missing ';' before 'constant'
Error 7 error C2106: '=' : left operand must be l-value
Error 8 error C2065: 'Temperatures' : undeclared identifier
Error 9 error C2275: 'std::array<int,24>' : illegal use of this type as an expression

Error 10 error C3861: 'Sleep': identifier not found
Error 21 error C2660: 'DisplayTemperatures' : function does not take 4 arguments

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
//main.cpp//
#include<iostream>	// for cin,cout
#include<limits> // Required for numeric_limits
#include<array> 
#include<ctime> 
#include"test.cpp" 
#include"weather.h"
using namespace std;


int main()
{
	// declare local constant(s), variable(s), and array(s)

	array<int, 24> HourlyTemperatures;
	const int NUM_TEMPERATURES = 24;
	int AverageTemp = 0;
	char run;
	cout << endl;
	cout << "Press 'A' continue - Press 0 to quit.";
	cin >> run;
	do
	{
		GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		AverageTemp = ComputeAverageTemp(Temperatures);
		Sleep(1500);
		int lowTemp = Low(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		int highTemp = High(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, AverageTemp, lowTemp, highTemp); //update your header prototype for DisplayTemperatures
		Sleep(3500);


	} while (run == 0);
	cout << " Okay - Another Time ";
	return 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
//test.cpp//
#include<iostream>	// for cin,cout
#include<iomanip>	// for formatting cout
#include<array>
#include"weather.h"	// for linking to main cpp file
using namespace std;

void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures)
{
	int CurrentTemp = 0;
	for (int i = 0; i < NUM_TEMPERATURES; i++)
	{
		cout << "Input hourly temp: ";
		cin >> Temperatures[i];
		while ((Temperatures[i] > 130) || (Temperatures[i]< -50))
		{
			cout << "Out of range - Try Again";
			--i;
		}
	}
}
// takes the values in the array and returns high, low, and mean
int ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
{
	//average the values in the array
	int sum = 0;
	for (int i = 0; i < NUM_TEMPERATURES; i++)
	{
		sum += Temperatures[i];
	}
	AverageTemp = sum / NUM_TEMPERATURES;
	return AverageTemp;
}
int High(array<int, NUM_TEMPERATURES>& Temperatures);
{
	//find the highest value in the array
	int highValue = Temperatures[0];
	for (int i = 0; i<NUM_TEMPERATURES; i++)
	{
		if (Temperatures[i] > highValue)
		{
			highValue = Temperatures[i];
		}
	}
	return highValue;
}
int Low(array<int, NUM_TEMPERATURES>& Temperatures);
{
	//find the lowest value in the array
	int lowValue = Temperatures[0];
	for (int i = 0; i <NUM_TEMPERATURES; i++)
	{
		if (Temperatures[i] < lowValue)
		{
			lowValue = Temperatures[i];
		}
	}
	return lowValue;
}
// displays the full run of values, the high, low, and mean
void DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
{
	cout << fixed << setprecision(2);
	cout << "Hour" << setw(9) << "Temperature\n";
	for (int x = 0; x<10; ++x)
	{
		cout << setw(2) << "0" << x << ":00" << setw(7) << Temperatures[x] << endl;
	}
	for (x = 10; x<NUM_TEMPERATURES; ++x)
	{
		cout << setw(3) << x << ":00" << setw(7) << Temperatures[x] << endl;
	}
	Sleep(1500);
	cout << setw(8) << "High" << setw(9) << highTemp << endl;
	cout << setw(8) << "Low" << setw(9) << lowTemp << endl;
	cout << setw(8) << "Average" << setw(9) << AverageTemp << endl;
	return;
}





test.cpp

For error 1 (and presumably errors 2-5), get rid of all those semicolons after your function headers. These are not function prototypes. These are function definitions, and you should not make the compiler think that the function header and function body are separate.

I'm not sure what to make of the warnings.

main.cpp

Not sure what error 6 means.

Error 7 is because you used #define NUM_TEMPERATURES 24 in your header file. This is a preprocessor directive, and means that before compiling, your compiler will replace all NUM_TEMPERATURES with 24.

In other words, to the compiler line 16 is const int 24 = 24;.

Error 8, where did you get Temperatures from? You did not declare it in the code. You only declared something called HourlyTemperatures.

Error 9, in your main function, you are trying to assign values to variables by using function calls. Except that you are not doing it correctly. Look up the difference between function calls and function prototypes.

Error 10, the Sleep function is not defined in any of the libraries you included. It is a function from the windows.h library.

Error 21, I assume you already know the problem and how to fix it from your comment.
Last edited on
Thank you

I was able to solve some errors based on your note. However, I still have got about 15 errors. I didnt understood which line's semicolon i should remove, so I m still getting same error.
Following are the errors i m getting.


Test.cpp
Error1-3 error C2059: syntax error : ')'
Error 4 error C2143: syntax error : missing ';' before '{'
Error 5-8 error C2447: '{' : missing function header (old-style formal list?)
Error 9 IntelliSense: expected a '{' introducing a lambda body
Error 10 IntelliSense: expected a type specifier
Error11 IntelliSense: expected an expression
Error12-15 IntelliSense: expected a declaration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//header file//

#ifndef weather_h // Avoid duplicate compilations
#define weather_h
#include <array>
#define NUM_TEMPERATURES 24
#define Temperatures
void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures);
int ComputeAverageTemp(std::array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
void DisplayTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
int Low(std::array<int, NUM_TEMPERATURES>& Temperatures);
int High(std::array<int, NUM_TEMPERATURES>& Temperatures);
#endif




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
//main.cpp//

#include<iostream>	// for cin,cout
#include<limits> // Required for numeric_limits
#include<array> 
#include<ctime> 
#include"test.cpp" 
#include"weather.h"
#include <windows.h> 
using namespace std;


int main()
{
	// declare local constant(s), variable(s), and array(s)

	array<int, 24> HourlyTemperatures;
	const int 24 = 24;
	int Temperature[24];
	int AverageTemp = 0;
	char run;
	cout << endl;
	cout << "Press 'A' continue - Press 0 to quit.";
	cin >> run;
	do
	{
		GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		AverageTemp = ComputeAverageTemp(Temperatures);
		Sleep(1500);
		int lowTemp = Low(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		int highTemp = High(array<int, NUM_TEMPERATURES>& Temperatures);
		Sleep(1500);
		DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, AverageTemp, lowTemp, highTemp); //update your header prototype for DisplayTemperatures
		Sleep(3500);


	} while (run == 0);
	cout << " Okay - Another Time ";
	return 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
//test.cpp//
#include<iostream>	// for cin,cout
#include<iomanip>	// for formatting cout
#include<array>
#include"weather.h"	// for linking to main cpp file
using namespace std;

void GetTemperatures(array<int, NUM_TEMPERATURES>& Temperatures)
{
	int CurrentTemp = 0;
	for (int i = 0; i < NUM_TEMPERATURES; i++)
	{
		cout << "Input hourly temp: ";
		cin >> Temperatures[i];
		while ((Temperatures[i] > 130) || (Temperatures[i]< -50))
		{
			cout << "Out of range - Try Again";
			--i;
		}
	}
}
// takes the values in the array and returns high, low, and mean
int ComputeAverageTemp(array<int, NUM_TEMPERATURES>& Tempeartures, int AverageTemp);
{
	//average the values in the array
	int sum = 0;
	for (int i = 0; i < NUM_TEMPERATURES; i++)
	{
		sum += Temperatures[i];
	}
	AverageTemp = sum / NUM_TEMPERATURES;
	return AverageTemp;
}
int High(array<int, NUM_TEMPERATURES>& Temperatures);
{
	//find the highest value in the array
	int highValue = Temperatures[0];
	for (int i = 0; i<NUM_TEMPERATURES; i++)
	{
		if (Temperatures[i] > highValue)
		{
			highValue = Temperatures[i];
		}
	}
	return highValue;
}
int Low(array<int, NUM_TEMPERATURES>& Temperatures);
{
	//find the lowest value in the array
	int lowValue = Temperatures[0];
	for (int i = 0; i <NUM_TEMPERATURES; i++)
	{
		if (Temperatures[i] < lowValue)
		{
			lowValue = Temperatures[i];
		}
	}
	return lowValue;
}
// displays the full run of values, the high, low, and mean
void DisplayTemperatures(array<int, NUM_TEMPERATURES>& Temperatures, int AverageTemp);
{
	cout << fixed << setprecision(2);
	cout << "Hour" << setw(9) << " Temperature\n";
	for (int x = 0; x<10; ++x)
	{
		cout << setw(2) << "0" << x << ":00" << setw(7) << Temperatures[x] << endl;
	}
	for (x = 10; x< NUM_TEMPERATURES; ++x)
	{
		cout << setw(3) << x << ":00" << setw(7) << Temperatures[x] << endl;
	}
	Sleep(1500);
	cout << setw(8) << "High" << setw(9) << highTemp << endl;
	cout << setw(8) << "Low" << setw(9) << lowTemp << endl;
	cout << setw(8) << "Average" << setw(9) << AverageTemp << endl;
	return;
}






You obviously didn't understand most of what I said in my last post. You should really review the basics.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int add(int a, int b); // this is a function prototype

int main()
{
    int one = 1;
    int two = 2;
    std::cout << add(one, two) << std::endl; // this is a function call
                                             // notice you don't give variable type
    return 0;
}

// this is a function definition
int add(int a, int b) // this is the function header, notice there is no semicolon
{
    // the stuff in these brackets is the function body
    return a + b;
}


What I said about the const int 24 = 24; meant that you should get rid of that line. That's because the left side of an assignment operation always has to be a variable. Also, you can never declare a variable with a name that starts with a number.
Or you could not use a macro, but a constant.
It should be obvious that it has to be visible before being used
1
2
const int NUM_TERMPERATURES = 24;
void GetTemperatures(std::array<int, NUM_TEMPERATURES>& Temperatures);
Topic archived. No new replies allowed.