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;
}
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)
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.
#include <iostream>
usingnamespace 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)
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?