Code won't compile

Hello, looking for some eyes to help with getting my code to compile.

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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>
#include <cstdlib> 
#include <iomanip>
using namespace std;
//func prototyping
int beginGame(int playedBoard[]);
void displayBoard(int board[][3]);
void instructions();
bool testWinner(int ans, int boardNum, int ansBoard[]);
int main()
{
	//Board "0" in c++
	int board1[4][3] = { 38, 11, 83,
		15, 6, 33,
		10, 2, 20,
		86, NULL, 95 };
	int board2[4][3] = { 28, 10, 55,
		89, 17, 98,
		22, 4, 31,
		69, NULL, 78 };
	int board3[4][3] = { 90, 9, 45,
		66, 12, 48,
		34, 7, 70,
		44, NULL, 26 };
	int ansArray[3] = { 14,15,8 };

	int usedBoards[3] = { NULL };
	int userInput, NumberOfWins = 0, guesses = 0, boardNumber, ans, randomNum;
	bool correct;
	int main_board[4][3];
	instructions(); //call upon instructions
	beginGa me(usedBoards);
	do
	{
		displayBoard(main_board);
		cout << endl << "Enter your guess or zero to exit";
		cin >> userInput;
		if (userInput == 0) {
			cout << endl << "Quitting";
			return 0;
		}
		else {
			while (userInput <0)
				cin >> userInput;
		}
	} while
		(testWinner(userInput, boardNumber, ansArray));
	if (correct == true)
	{
		switch (boardNumber)
		{
		case 0:
			NumberOfWins++;
			usedBoards[0] = 1;
		}

	}

	else if (correct == true && ((usedBoards[0] != NULL) || (usedBoards[1] != NULL) || (usedBoards[2] != NULL)))

	{
		cout << endl << "Do you want to play again or exit (0)";
		cin >> userInput;
		if (userInput == 0) {
			cout << endl << "Quitting";
			return 0;
		}

		else {

			while (userInput < 0)
			{
				cout << endl << "Please enter a valid value";
				cin >> userInput;
			}

		}

		if (userInput != 0)
		{
			beginGame(usedBoards);
		}

	}
	else
	{
		guesses++;
		if (guesses > 3)
		{
			cout << endl << "Do you want to play again?. 1 to play again, 0 to exit";
			cin >> userInput;
			if (userInput == 0) {
				cout << endl << "Quitting";
				return 0;
			}

			else {

				while (userInput < 0)
				{
					cout << endl << "Please enter a valid value";
					cin >> userInput;
				}

			}

			if (userInput != 0)
			{
				beginGame(usedBoards);
			}
		}
	}
	while (usedBoards[0] != NULL || usedBoards[1] != NULL || usedBoards[2] != NULL);
	cout << endl << "You are the number guessing Champion";
	return 0;
}


	}

	{
		{
		}
		return 0;
	}

	int beginGame(int playedBoard[])
	{
		int randomNum;
		int boardNum;
		//Generate a random number between 1 and 3
		//check to see if this board has not been played
		//return random number
		//else loop back around and generate new random number
		{
			int randomNum;
			while (true) {
				randomNum = rand() % 3;
				if (playedBoards[randomNum] != 1)// if not already played
					break;
			}
			return randomNum;
		}
	}

	void displayBoard(int board[][3])
	{
		//remember to display ? look for NULL value, i.e if NULL
		//Hint you will need two for loops
		{
			for (int x = 0; x < 4; x++)
			{
				for (int y = 0; y < 3; y++)
				{
					cout << setw(4) << board[x][y] << " ";
				}
				cout << endl;
			}
		}
	}

	void instructions()
	{
		cout << "**********************************" << endl;
		cout << endl << "MISSING NUMBERS GAME" << endl;
		cout << "A Fun Brain Game" << endl << endl << endl;
		cout << "Please enter a whole number to guess the missing number...";
		cout << endl << "Program Developed by: Austin Sisti" << endl;
		cout << "**********************************" << endl;
	}

	bool testWinner(int ans, int boardNum, int ansBoard[])
	{
		//check to see if the ans <which is the answer that the user entered) is equal to 
		//the answer in the ansBoard.
		//if answered correnctly output nice job... and return true
		//else output incorrect... and return false
		{
			if (ans == ansBoard[boardNum])
			{
				cout << endl << "Nice Job!!";
				return true;
			}
			else
			{
				cout << endl << "Sorry, that is incorrect";
				return false;
			}
		}
	}


main.cpp: At global scope:
main.cpp:125:2: error: expected declaration before '}' token
}
^
The closing brace of the main() seems to be on line 116.

Line 127 seems to start a definition of a function.

What is on lines 119--125?
im actually not really sure what had happened there but I've fixed thank you!
so now my code has a strange output any idea why?
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iostream>
#include <cstdlib> 
#include <iomanip>
using namespace std;
//func prototyping
int beginGame(int playedBoard[]);
void displayBoard(int board[][3]);
void instructions();
bool testWinner(int ans, int boardNum, int ansBoard[]);
int main()
{
	//Board "0" in c++
	int board1[4][3] = { 38, 11, 83,
		15, 6, 33,
		10, 2, 20,
		86, NULL, 95 };
	int board2[4][3] = { 28, 10, 55,
		89, 17, 98,
		22, 4, 31,
		69, NULL, 78 };
	int board3[4][3] = { 90, 9, 45,
		66, 12, 48,
		34, 7, 70,
		44, NULL, 26 };
	int ansArray[3] = { 14,15,8 };

	int usedBoards[3] = { NULL };
	int userInput, NumberOfWins = 0, guesses = 0, boardNumber, ans, randomNum;
	bool correct;
	int main_board[4][3];
	instructions(); //call upon instructions
	beginGame(usedBoards);
	do
	{
		displayBoard(main_board);
		cout << endl << "Enter your guess or zero to exit";
		cin >> userInput;
		if (userInput == 0) {
			cout << endl << "Quitting";
			return 0;
		}
		else {
			while (userInput <0)
				cin >> userInput;
		}
	} while
		(testWinner(userInput, boardNumber, ansArray));
	if (correct == true)
	{
		switch (boardNumber)
		{
		case 0:
			NumberOfWins++;
			usedBoards[0] = 1;
		}

	}

	else if (correct == true && ((usedBoards[0] != NULL) || (usedBoards[1] != NULL) || (usedBoards[2] != NULL)))

	{
		cout << endl << "Do you want to play again or exit (0)";
		cin >> userInput;
		if (userInput == 0) {
			cout << endl << "Quitting";
			return 0;
		}

		else {

			while (userInput < 0)
			{
				cout << endl << "Please enter a valid value";
				cin >> userInput;
			}

		}

		if (userInput != 0)
		{
			beginGame(usedBoards);
		}

	}
	else
	{
		guesses++;
		if (guesses > 3)
		{
			cout << endl << "Do you want to play again?. 1 to play again, 0 to exit";
			cin >> userInput;
			if (userInput == 0) {
				cout << endl << "Quitting";
				return 0;
			}

			else {

				while (userInput < 0)
				{
					cout << endl << "Please enter a valid value";
					cin >> userInput;
				}

			}

			if (userInput != 0)
			{
				beginGame(usedBoards);
			}
		}
	}
	while (usedBoards[0] != NULL || usedBoards[1] != NULL || usedBoards[2] != NULL);
	cout << endl << "You are the number guessing Champion";
	return 0;
}


	int beginGame(int playedBoard[])
	{
		int randomNum;
		int boardNum;
		//Generate a random number between 1 and 3
		//check to see if this board has not been played
		//return random number
		//else loop back around and generate new random number
		{
			int randomNum;
			while (true) {
				randomNum = rand() % 3;
				if (playedBoard[randomNum] != 1)// if not already played
					break;
			}
			return randomNum;
		}
	}

	void displayBoard(int board[][3])
	{
		//remember to display ? look for NULL value, i.e if NULL
		//Hint you will need two for loops
		{
			for (int x = 0; x < 4; x++)
			{
				for (int y = 0; y < 3; y++)
				{
					cout << setw(4) << board[x][y] << " ";
				}
				cout << endl;
			}
		}
	}

	void instructions()
	{
		cout << "**********************************" << endl;
		cout << endl << "MISSING NUMBERS GAME" << endl;
		cout << "A Fun Brain Game" << endl << endl << endl;
		cout << "Please enter a whole number to guess the missing number...";
		cout << endl << "Program Developed by: Austin Sisti" << endl;
		cout << "**********************************" << endl;
	}

	bool testWinner(int ans, int boardNum, int ansBoard[])
	{
		//check to see if the ans <which is the answer that the user entered) is equal to 
		//the answer in the ansBoard.
		//if answered correnctly output nice job... and return true
		//else output incorrect... and return false
		{
			if (ans == ansBoard[boardNum])
			{
				cout << endl << "Nice Job!!";
				return true;
			}
			else
			{
				cout << endl << "Sorry, that is incorrect";
				return false;
			}
		}
	}

Please enter a whole number to guess the missing number...
Program Developed by: Austin Sisti
**********************************
124 0 0
0 4199312 0
4197430 0 -733832048
32764 0 0

Enter your guess or zero to exit
any idea why?

There’s a number of errors, so it’s hard to say what’s the main problem.

1) ‘NULL’ is a special value created for pointers; assigning it to integers is at least confusing: use 0 instead.
In case you really need ‘NULL’, please remember C++ introduced ‘nullptr’.

2) When you pass a C-style array to a function, it decays into a pointer. It means these two declarations are equivalent:
void myfunc(int myvalues[]);
void myfunc(int * myvalues);
So, when you pass a C-style array to a function, you usually want to add its dimension as additional parameters:
void myfunc(int * myvalues, unsigned size);

3) Arrays indexes start from 0, so arrays highest index is equal to their size less one.
Look at beginGame(), for example. You pass it an array declared this way:
int usedBoards[3] = { NULL };
And then you test its boundaries by there instructions:
1
2
randomNum = rand() % 3;
if (playedBoard[randomNum] != 1)


4) When you call displayBoard(main_board); the first time, “main_board” hasen’t been initialised yet.

I’d also point out a weird syntax that’s not going to give you troubles in this case, but could betray you in the future, for example if you used bidimensional std::vectors.
Look at this definition:
1
2
3
4
int board1[4][3] = { 38, 11, 83,
    15, 6, 33,
    10, 2, 20,
    86, NULL, 95 };

Memory cells ‘lie’ one next to the other, so a 4 x 3 array is nothing but a 12-cells array. That’s way the compiler can interpret your instruction correctly and assign the proper value to every memory cell without errors.
But the definition itself doesn’t represent a 4 x 3 array, because newlines are ignored by the compiler. What counts are commas. I mean: if you put all those data in one line, the compiler would read it the same way. Instead a 4 x 3 initialisation would look like:
1
2
3
4
int board1[4][3] = { { 38, 11, 83 },
                     { 15, 6, 33 },
                     { 10, 2, 20 },
                     { 86, 0, 95 }  };

A bidimensional std::vector would reject incorrect initialisation syntax.

What’s above is what I spotted at first glance. Let me suggest you to search your IDE for some re-indentation option to tidy up your code.

Happy coding!
Topic archived. No new replies allowed.