Why am I getting these error mesages?

I am getting the following error messages when I compile:

sudoku-modified.cpp(82) : error C2628: 'Sudoku' followed by 'void' is illegal (did you forget a ';'?)
1>e:\sudoku-modified.cpp(87) : error C2065: 'gameboard' : undeclared identifier
1>e:\sudoku-modified.cpp(32) : error C3861: 'Checkwinner': identifier not found
1>e:\sudoku-modified.cpp(108) : error C2065: 'gameboard' : undeclared identifier
1>e:\sudoku-modified.cpp(121) : error C2039: 'Read' : is not a member of 'Sudoku'
1> e:\sudoku-modified.cpp(6) : see declaration of 'Sudoku'
1>e:\sudoku-modified.cpp(122) : error C2039: 'PrintBoard' : is not a member of 'Sudoku'
1> e:\sudoku-modified.cpp(6) : see declaration of 'Sudoku'
1>Build log was saved at "file://c:\Documents and Settings\Allen\My Documents\Visual Studio 2008\Projects\Project 6\Project 6\Debug\BuildLog.htm"
1>Project 6 - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here the the code to my program:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

class Sudoku{

private:
int gameboard[9][9];
int count;


public:
Sudoku(){
for (int i=0;i<9;i++)
for (int j=0; j<9; j++)
gameboard[i][j] = 0;

}
void MakeMove (/*int gameboard[ ][9], int r, int c, int num*/) {
int r;
int c;
int num;
//cout << "Enter move (row, column and number 1-9): ";
// cin >> r >> c >> num;
for (int i=0;!Finished();i++){
cout << "Enter move (row, column and number 1-9): ";
cin >> r >> c >> num;
if (gameboard[r][c] == 0)
gameboard[r-1][c-1] = num;
PrintBoard(/*gameboard*/);
Checkwinner(/*gameboard*/);
count++;}
return;
}

bool Finished(){
count = 0;
for (int i=0;i<9;i++)
for (int j=0; j<9; j++)
if (gameboard[i][j] > 0) count++;
return (count == 81);
//if (count < 81) return false;
//return true;
}


void CheckWinner (/*int gameboard[ ][9]*/) {

if (!Finished())
cout << "Ok for now. Keep going" << endl;
else // Full
cout << "Game Over"<<endl;

return;
}

}


void PrintBoard (/*int gameboard[][9]*/) {
cout << "\t+---+---+---+---+---+---+---+---+---+---+----+" << endl;
for (int a=0; a<9; a++) {
cout << "\t| ";
for (int b=0; b<9; b++){
cout << gameboard[a][b];
cout << " | ";
cout << endl;
cout << "\t+---+---+---+---+---+---+---+---+---+---+----+" << endl;}
}
}



void Read (){
ifstream sudoku_board;
sudoku_board.open("sudoku_game.txt");
if (sudoku_board.fail())
{
cout << "Input file opening failed." << endl;
exit(1);
}
//sudoku_board >> gameboard[a][b];
while (!sudoku_board.eof()){
for (int c=0;c<9;c++)
for (int d=0;d<9;d++)
sudoku_board >> gameboard[c][d];

sudoku_board.close();
}

};





int main ( ) {
Sudoku u;
u.Read();
u.PrintBoard();
u.MakeMove();
u.CheckWinner();
//int gameboard[9][9];



return 0;
}

You close the bracket for the class too early...(line 58 you have one more closing bracket that acts like a closing bracket for the class and it says that you forgot the ";")
Also line 39 you have Checkwinner(). it needs to be "CheckWinner()" (winner with capital W)

Hope this helps
Last edited on
thanks a lot, that was very helpful
You must remember that when you declare and initialise the function in the class then it is automatically inline function. This means that every time your program has a call to that function it will replace the call with the code from your function.
This can make the program run faster but it will make the size of the file bigger, especially if there are many calls to the function and the function code is big. Usually it is better to have as inline only small functions.

To avoid something like that declare the function in the class but write their code outside of the class declaration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
class myClass{
   int num;
public:
   void set_num(int x){ //inline function
      num = x;
   }
   int ret_num();//normal function
};
int myClass::ret_num(){
   return num;
}

int main(){
   myClass obj;
   obj.set_num(5);
   cout << obj.ret_num();
   return 0;
}


(sorry, I'm not good explaining it, but I hope you get what I mean)
Last edited on
What is a good way to check to see if the rows and columns of the board are not equal? I think maybe if I used a temp array to check each row and column, that would work, but I am having a hard time coding that. Is there a better way?
You can check each row and each column individually.
If you don't find any dublicated numbers in a column or a row then you don't have an equallity.
Topic archived. No new replies allowed.