New to C++....Help please?

Here is my code. Im getting a error C2447: '{' : missing function header (old-style formal list?) error and i have no idea what this is. any help would be appreciated.....,. Thanks

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
//Round Robin Sim
#include <iostream>
#include <cstdlib>
using namespace std;

template<class T>
int main(void);

struct Job {
		double JArriveTime;
		double JServiceTime;
		double JRemainingTime;
		double JEndTime;
};
Job Queue[5];

bool JobsWithTimeLeft();


//Declarations
	double TimeQ, CSOH;
	double AvgWaitTime = 0;
	double AvgTATime = 0;
	double CurrTime = 0;
	int i;
	
	{
//Input
	cout << "Please enter the TIme Quantum between 1 and 5 (ms): ";
	cin >> TimeQ;
	//Add code to check user entry later!
	cout << "Please enter Context Switch Overhead bewteen 0 and 250 (ms): ";
	cin >> CSOH;
	//Add code to check user entry later!

	//Convert the time quantum and overhead from ms to sec
	TimeQ = TimeQ / 1000;
	CSOH = CSOH / 1000;

	//Polulate the array with hardcoded values now
	//Add Code to read from data file later
	Queue[0].JArriveTime = 30;
	Queue[0].JServiceTime = .078356;
	Queue[1].JArriveTime = 54;
	Queue[1].JServiceTime = 17.282004;
	Queue[2].JArriveTime = 97;
	Queue[2].JServiceTime = 32.814544;
	Queue[3].JArriveTime = 133;
	Queue[3].JServiceTime = 39.98673;
	Queue[4].JArriveTime = 163;
	Queue[4].JServiceTime = 42.805902;

	for (i=0; i<5; i++)  {
		Queue[i]. JRemainingTime = Queue[i].JServiceTime;
		Queue[i]. JEndTime = 0;

	}

//Process
	while (JobsWithTimeLeft()){
		for (i=0; i<5; i++) {
			if ((Queue[i].JArriveTime <= CurrTime) &&
				(Queue[i].JRemainingTime > 0)) {
					Queue[i].JRemainingTime = Queue[i].JRemainingTime -TimeQ;
					CurrTime = CurrTime + TimeQ;
					if (Queue[i].JRemainingTime < 0){
						CurrTime = CurrTime + Queue[i].JRemainingTime;
						Queue[i].JRemainingTime = 0;
					}
					if (Queue[i].JRemainingTime =0)
					Queue[i].JEndTime = CurrTime;
			}
		}
		CurrTime = CurrTime + .1;
	}
	
//Output
	cout << "\nThe Average Wait Time was " << AvgWaitTime << endl;
	cout << "The Average Turnaround time was " << AvgTATime << endl;
	cout << "The array at the end looks like " << endl;
	cout << "\nArrive  Sercive  Remaining  End" <<endl;
	for (i=0; i<5; i++) {
		cout << Queue [i].JArriveTime << "      ";
		cout << Queue [i].JServiceTime << "      ";
		cout << Queue [i].JRemainingTime << "     ";
		cout << Queue [i].JEndTime << "     " << endl; }

	system("PAUSE");



bool JobsWithTimeLeft() {
	bool Found = false;
	for (int i = 0; i < 5; i++) {
		if (Queue[i].JRemainingTime > 0)
			Found = true;
	}
	return Found;
}
	}
closed account (z05DSL3A)
I think, giving it a quick scan, that you have missed out int main... you have a 'pointless' declaration of main at line 7 but no definition, I would assume that it should be around line 27. The error is refering to the openiing brace on line 27.

also the closing brace at line 100 should be above JobsWithTimeLeft(),

Try changing your code arounld line 20 to:
1
2
3
4
5
6
7
8
9
10
11
12
int main(void)
{
//Declarations
	double TimeQ, CSOH;
	double AvgWaitTime = 0;
	double AvgTATime = 0;
	double CurrTime = 0;
	int i;
	
//Input
	cout << "Please enter the TIme Quantum between 1 and 5 (ms): ";
...
Last edited on
It is trying to make main() a template function. My compiler (g++) complains with the following errors:

test.cpp:7: error: cannot declare `::main' to be a template
test.cpp:27: error: expected unqualified-id before '{' token

The first is just as I described. The second is due to the fact that you have a block of code that doesn't belong to a function, a class, etc.

All your code has matches for opening/closing delimiters, it seems. However, once you fix those issues, you'll need to adjust your braces, just as Grey Wolf suggested. After all, you can't have the JobsWithTimeLeft() function inside the main() function.

I hope we helped!
I completed all of those updates and im still getting these errors. Heres the errors and the code again thanks

1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(15) : error C2955: 'Job' : use of class template requires template argument list
1> c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(14) : see declaration of 'Job'
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(15) : error C2148: total size of array must not exceed 0x7fffffff bytes
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(15) : error C2512: 'Job' : no appropriate default constructor available
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(20) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(102) : fatal error C1004: unexpected end-of-file found

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
//Round Robin Sim
#include <iostream>
#include <cstdlib>
using namespace std;

template<class T>


struct Job {
		double JArriveTime;
		double JServiceTime;
		double JRemainingTime;
		double JEndTime;
};
Job Queue[3];

bool JobsWithTimeLeft();

int main(void);
{
//Declarations
	double TimeQ, CSOH;
	double AvgWaitTime = 0;
	double AvgTATime = 0;
	double CurrTime = 0;
	int i;
	
	
//Input
	cout << "Please enter the TIme Quantum between 1 and 5 (ms): ";
	cin >> TimeQ;
	//Add code to check user entry later!
	cout << "Please enter Context Switch Overhead bewteen 0 and 250 (ms): ";
	cin >> CSOH;
	//Add code to check user entry later!

	//Convert the time quantum and overhead from ms to sec
	TimeQ = TimeQ / 1000;
	CSOH = CSOH / 1000;

	//Polulate the array with hardcoded values now
	//Add Code to read from data file later
	Queue[0].JArriveTime = 30;
	Queue[0].JServiceTime = .078356;
	Queue[1].JArriveTime = 54;
	Queue[1].JServiceTime = 17.282004;
	Queue[2].JArriveTime = 97;
	Queue[2].JServiceTime = 32.814544;
	Queue[3].JArriveTime = 133;
	Queue[3].JServiceTime = 39.98673;
	Queue[4].JArriveTime = 163;
	Queue[4].JServiceTime = 42.805902;

	for (i=0; i<5; i++)  {
		Queue[i]. JRemainingTime = Queue[i].JServiceTime;
		Queue[i]. JEndTime = 0;

	}

//Process
	while (JobsWithTimeLeft()){
		for (i=0; i<5; i++) {
			if ((Queue[i].JArriveTime <= CurrTime) &&
				(Queue[i].JRemainingTime > 0)) {
					Queue[i].JRemainingTime = Queue[i].JRemainingTime -TimeQ;
					CurrTime = CurrTime + TimeQ;
					if (Queue[i].JRemainingTime < 0){
						CurrTime = CurrTime + Queue[i].JRemainingTime;
						Queue[i].JRemainingTime = 0;
					}
					if (Queue[i].JRemainingTime =0)
					Queue[i].JEndTime = CurrTime;
			}
		}
		CurrTime = CurrTime + .1;
	}
	
//Output
	cout << "\nThe Average Wait Time was " << AvgWaitTime << endl;
	cout << "The Average Turnaround time was " << AvgTATime << endl;
	cout << "The array at the end looks like " << endl;
	cout << "\nArrive  Sercive  Remaining  End" <<endl;
	for (i=0; i<5; i++) {
		cout << Queue [i].JArriveTime << "      ";
		cout << Queue [i].JServiceTime << "      ";
		cout << Queue [i].JRemainingTime << "     ";
		cout << Queue [i].JEndTime << "     " << endl; }

	system("PAUSE");


	{
bool JobsWithTimeLeft() {
	bool Found = false;
	for (int i = 0; i < 5; i++) {
		if (Queue[i].JRemainingTime > 0)
			Found = true;
	}
	return Found;
}
	
Why is that
template <class T>
there? You aren't using templates in your code. The compiler is complaining about the fact that you declared Job as
1
2
template <class T>
struct Job {


Also, remove the semicolon from
int main(void);

That should help quite a bit.
I did that and i still get these errors:

1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(18) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(18) : warning C4091: '' : ignored on left of 'void' when no variable is declared
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(19) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\matt\documents\visual studio 2005\projects\project 1\project 1\1.cpp(100) : fatal error C1004: unexpected end-of-file found
These should be the changes thus far:
1
2
3
using namespace std;

struct Job {


1
2
3
4
5
bool JobsWithTimeLeft();

int main(void)
{
//Declarations 


1
2
3
4
	system("PAUSE");
}

bool JobsWithTimeLeft() {


I believe that should do it. It compiles for me in both Visual C++ 2008 Express Edition and g++ (MinGW) 3.4.5 if I substitute your code for those changes.

I hope it works! ^_^
Last edited on
These error still pop up.

error C2144: syntax error : 'void' should be preceded by ';'
warning C4091: '' : ignored on left of 'void' when no variable is declared
error C2447: '{' : missing function header (old-style formal list?)
closed account (z05DSL3A)
I have only made the changes that are pointed out above and this compiles:
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
//Round Robin Sim
#include <iostream>
#include <cstdlib>
using namespace std;




struct Job {
		double JArriveTime;
		double JServiceTime;
		double JRemainingTime;
		double JEndTime;
};
Job Queue[3];

bool JobsWithTimeLeft();

int main(void)
{
//Declarations
	double TimeQ, CSOH;
	double AvgWaitTime = 0;
	double AvgTATime = 0;
	double CurrTime = 0;
	int i;
	
	
//Input
	cout << "Please enter the TIme Quantum between 1 and 5 (ms): ";
	cin >> TimeQ;
	//Add code to check user entry later!
	cout << "Please enter Context Switch Overhead bewteen 0 and 250 (ms): ";
	cin >> CSOH;
	//Add code to check user entry later!

	//Convert the time quantum and overhead from ms to sec
	TimeQ = TimeQ / 1000;
	CSOH = CSOH / 1000;

	//Polulate the array with hardcoded values now
	//Add Code to read from data file later
	Queue[0].JArriveTime = 30;
	Queue[0].JServiceTime = .078356;
	Queue[1].JArriveTime = 54;
	Queue[1].JServiceTime = 17.282004;
	Queue[2].JArriveTime = 97;
	Queue[2].JServiceTime = 32.814544;
	Queue[3].JArriveTime = 133;
	Queue[3].JServiceTime = 39.98673;
	Queue[4].JArriveTime = 163;
	Queue[4].JServiceTime = 42.805902;

	for (i=0; i<5; i++)  {
		Queue[i]. JRemainingTime = Queue[i].JServiceTime;
		Queue[i]. JEndTime = 0;

	}

//Process
	while (JobsWithTimeLeft()){
		for (i=0; i<5; i++) {
			if ((Queue[i].JArriveTime <= CurrTime) &&
				(Queue[i].JRemainingTime > 0)) {
					Queue[i].JRemainingTime = Queue[i].JRemainingTime -TimeQ;
					CurrTime = CurrTime + TimeQ;
					if (Queue[i].JRemainingTime < 0){
						CurrTime = CurrTime + Queue[i].JRemainingTime;
						Queue[i].JRemainingTime = 0;
					}
					if (Queue[i].JRemainingTime =0)
					Queue[i].JEndTime = CurrTime;
			}
		}
		CurrTime = CurrTime + .1;
	}
	
//Output
	cout << "\nThe Average Wait Time was " << AvgWaitTime << endl;
	cout << "The Average Turnaround time was " << AvgTATime << endl;
	cout << "The array at the end looks like " << endl;
	cout << "\nArrive  Sercive  Remaining  End" <<endl;
	for (i=0; i<5; i++) {
		cout << Queue [i].JArriveTime << "      ";
		cout << Queue [i].JServiceTime << "      ";
		cout << Queue [i].JRemainingTime << "     ";
		cout << Queue [i].JEndTime << "     " << endl; }

	system("PAUSE");


}
bool JobsWithTimeLeft() {
	bool Found = false;
	for (int i = 0; i < 5; i++) {
		if (Queue[i].JRemainingTime > 0)
			Found = true;
	}
	return Found;
}
Last edited on
Topic archived. No new replies allowed.