Expected Primary Expression Before Token

Pages: 12
eohama: on lines 62 & 66 you are only passing 5 parameters to compturn, but compturn is expecting 6.
Thanks wtf, I didn't see that.
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
#include <iostream>
#include <vector>
using namespace std ;

int main (int argc, char * const argv [] ) {
	// Method declarations
	void pseudoMain () ;
	
	pseudoMain () ;
	
	// Return before end of script
	cout << endl << endl ;
	return 0 ;
	}

void pseudoMain () {
	// Variable declarations
	char compFirstChar ;
	bool compFirst ;
	bool gameOver ;
	int poisonNum ;
	int max ;
	int lastNum ;
	int midlNum ;
	int enteredNum = 1 ;
	vector <int> stepStones ;
	
	// Method declarations
	void restart () ;
	void error (int errorCode) ;
	int determineStepStones (int stepStonesArray [] , int poisonNum, int max) ;
	int display (int lastNum, int enteredNum) ;
	int compTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) ;
	int userTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) ;
	
	// Set the variables
	cout << "Would you like the computer to go first (y|n) ?	" ;
	cin >> compFirstChar ;
	switch (compFirstChar) {
		case 'y' :
			compFirst = true ;
			break ;
			
		case 'n' :
			compFirst = false ;
			break ;

		default:
			error (1) ;
			break ;
		}
	cout << "Please enter a positive number to be the “poison” number:	" ;
	cin >> poisonNum ;
	cout << "Please enter a positive number to be the maximum number of numbers that a player may go through at any one time:	" ;
	cin >> max ;
	stepStones.resize (poisonNum / max) ;
	determineStepStones (vector <int> stepStones, poisonNum, max) ;
	
	// Start the game
	system ( "clear" ) ;
	
	if (compFirst == true) { lastNum = compTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
	while (gameOver == false) {
		if (gameOver == false) { lastNum = userTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
		else { break ; }
		if (gameOver == false) { lastNum = compTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
		else { break ; }
		}
	}

void restart () {
	cout << endl << "Restarting script…" << endl ;
	system ( "clear" ) ;
	pseudoMain () ;
	}

void error (int errorCode) {
	switch (errorCode) {
		case 0:
			cout << "Error 0 (983-853) : an unknown error has occured." ;
			restart () ;
			break ;
			
		case 1:
			cout << "Error 1 (96-483.23) : you did not enter a lowercase 'y' (for yes) or a lowercase 'n' (for no) when I asked you if you wanted the computer to go first.  Remember, computers are picky, so you must be pseudoperfect!"  << endl ;
			restart () ;
			break ;

		case 2:
			cout << "Error 2 (46-3662) : the number you have entered is not acceptable.  You must enter a number between the two numbers given." ;
			break ;
			
		default:
			error (0) ;
			break ;
		}
	}

int determineStepStones (vector <int> stepStones, int poisonNum, int max) {
	// This is backwards, but the resulting vector makes more sense.
	// Sets the last “stepping stone” number to what it is (the “poison” number minus one)
	stepStones [poisonNum / max] = poisonNum - 1 ;
	// Sets all of the rest of the “stepping stone” numbers to what they are (the previous “stepping stone” number minus max)
	for (int i = poisonNum / max ; i >= 0 ; i -- ) { stepStones [i] = stepStones [i - 1] - (max + 1) ; }
	}

int display (int lastNum, int enteredNum) {
	cout << endl ;
	for (int i = lastNum ; i <= enteredNum ; i ++ ) {
		cout << i << ", " ;
		}
	cout << enteredNum << endl ;
	}

int compTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) {
	enteredNum = midlNum ;
	
	for (int i = enteredNum ; i < enteredNum + max ; i ++ ) {
		for (int j = 0 ; j < poisonNum / max ; j ++ ) {
			if (i == stepStones [j] ) {
				display (lastNum, enteredNum) ;
				break ;
				}
			}
		}
	
	midlNum = lastNum ;
	return lastNum ;
	}

int userTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) {
	enteredNum = midlNum ;
	
	cout << "Enter a number above " << lastNum << " and below " << lastNum + max + 1 << " (exclusive) :	" ;
	cin >> enteredNum ;
	if (lastNum < enteredNum <= lastNum + max) { display (lastNum, enteredNum) ; }
	else {
		error (2) ;
		midlNum = enteredNum ;
		lastNum = userTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ;
		return lastNum ;
		}

	midlNum = lastNum ;
	return lastNum ;
	}


I'm getting
Expected primary-expression before 'stepStones'
on lines 56, 62, 64, 66, and 141. What am I doing wrong?
@wtf "My second question is WTF??? How in the heck did you manage to declare functions inside main()?" :

Well, Xcode inserted

int main (int argc, char * const argv [] ) {

for me, then I just put

1
2
// Method declarations
void pseudoMain () ;

underneath.
You're not supposed to declare or define functions in other functions...
Last edited on
I assume you mean other than int main () .

And why not?
You're not supposed to declare or define functions inside ANY functions, even main. Period. Functions are defined ore declared outside of everything, aka the global scope. Unless you're declaring/defining them in a class, which is OK because that is how you do it. But functions should not be inside other functions...it just doesn't make sense (and it doesn't compile for me!)
Okay, I moved all of the method declarations to between using namespace std; and int main… . Can anyone tell me what I'm doing wrong on lines 56, 62, 64, 66, and 141 (see five posts ago) ?
Last edited on
Can anyone tell me what I'm doing wrong on lines 55, 60, 62, 64, and 138 (see six posts ago) ?:

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

// Method declarations
void pseudoMain () ;
void restart () ;
void error (int errorCode) ;
int determineStepStones (int stepStonesArray [] , int poisonNum, int max) ;
int display (int lastNum, int enteredNum) ;
int compTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) ;
int userTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) ;

int main (int argc, char * const argv [] ) {
	pseudoMain () ;
	
	// Return before end of script
	cout << endl << endl ;
	return 0 ;
	}

void pseudoMain () {
	// Variable declarations
	char compFirstChar ;
	bool compFirst ;
	bool gameOver ;
	int poisonNum ;
	int max ;
	int lastNum ;
	int midlNum ;
	int enteredNum = 1 ;
	vector <int> stepStones ;
	
	// Set the variables
	cout << "Would you like the computer to go first (y|n) ?	" ;
	cin >> compFirstChar ;
	switch (compFirstChar) {
		case 'y' :
			compFirst = true ;
			break ;
			
		case 'n' :
			compFirst = false ;
			break ;

		default:
			error (1) ;
			break ;
		}
	cout << "Please enter a positive number to be the “poison” number:	" ;
	cin >> poisonNum ;
	cout << "Please enter a positive number to be the maximum number of numbers that a player may go through at any one time:	" ;
	cin >> max ;
	stepStones.resize (poisonNum / max) ;
	determineStepStones (vector <int> stepStones, poisonNum, max) ;
	
	// Start the game
	system ( "clear" ) ;
	
	if (compFirst == true) { lastNum = compTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
	while (gameOver == false) {
		if (gameOver == false) { lastNum = userTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
		else { break ; }
		if (gameOver == false) { lastNum = compTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ; }
		else { break ; }
		}
	}

void restart () {
	cout << endl << "Restarting script…" << endl ;
	system ( "clear" ) ;
	pseudoMain () ;
	}

void error (int errorCode) {
	switch (errorCode) {
		case 0:
			cout << "Error 0 (983-853) : an unknown error has occured." ;
			restart () ;
			break ;
			
		case 1:
			cout << "Error 1 (96-483.23) : you did not enter a lowercase 'y' (for yes) or a lowercase 'n' (for no) when I asked you if you wanted the computer to go first.  Remember, computers are picky, so you must be pseudoperfect!"  << endl ;
			restart () ;
			break ;

		case 2:
			cout << "Error 2 (46-3662) : the number you have entered is not acceptable.  You must enter a number between the two numbers given." ;
			break ;
			
		default:
			error (0) ;
			break ;
		}
	}

int determineStepStones (vector <int> stepStones, int poisonNum, int max) {
	// This is backwards, but the resulting vector makes more sense.
	// Sets the last “stepping stone” number to what it is (the “poison” number minus one)
	stepStones [poisonNum / max] = poisonNum - 1 ;
	// Sets all of the rest of the “stepping stone” numbers to what they are (the previous “stepping stone” number minus max)
	for (int i = poisonNum / max ; i >= 0 ; i -- ) { stepStones [i] = stepStones [i - 1] - (max + 1) ; }
	}

int display (int lastNum, int enteredNum) {
	cout << endl ;
	for (int i = lastNum ; i <= enteredNum ; i ++ ) {
		cout << i << ", " ;
		}
	cout << enteredNum << endl ;
	}

int compTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) {
	enteredNum = midlNum ;
	
	for (int i = enteredNum ; i < enteredNum + max ; i ++ ) {
		for (int j = 0 ; j < poisonNum / max ; j ++ ) {
			if (i == stepStones [j] ) {
				display (lastNum, enteredNum) ;
				break ;
				}
			}
		}
	
	midlNum = lastNum ;
	return lastNum ;
	}

int userTurn (int poisonNum, int max, int lastNum, int midlNum, int enteredNum, vector <int> stepStones) {
	enteredNum = midlNum ;
	
	cout << "Enter a number above " << lastNum << " and below " << lastNum + max + 1 << " (exclusive) :	" ;
	cin >> enteredNum ;
	if (lastNum < enteredNum <= lastNum + max) { display (lastNum, enteredNum) ; }
	else {
		error (2) ;
		midlNum = enteredNum ;
		lastNum = userTurn (poisonNum, max, lastNum, midlNum, enteredNum, vector <int> stepStones) ;
		return lastNum ;
		}

	midlNum = lastNum ;
	return lastNum ;
	}
@55: Remove vector <int>
@60: Remove vector <int>
@62: Remove vector <int>
@64: Remove vector <int>
@138: Remove vector <int>
Thank you (I'm new to this.…) .
Just one more thing: on line 55 I'm getting a
Expected primary-expression before ‘,’ token
error:

1
2
// line 55 (the rest of the lines are the same, except I removed “vector <int> ” five times:
determineStepStones (stepStones* , poisonNum, max) ;
…never mind, I figured it out (it was an outdated method declaration (from when I was using an array) ) .
You're not supposed to declare or define functions in other functions...

Minor point: it's perfectly legal to declare functions inside other functions (a function declaration is a simple-declaration[http://www.lcdf.org/c++/clauseA.html#sA.6], after all), though the name introduced by such is only visible within the function, so they're not much use (typedef-ing a function pointer, however...). Definitions, indeed, aren't allowed, even in C++0x with its support for closures.
You can in gnu c:
1
2
3
4
5
int *sort_ints(int * x, int n){
	int intcmp(int* x, int *y){return *x==*y?0:*x<*y?-1:1;}
	qsort(x,n,sizeof(int),&intcmp);
	return x;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 12