my solver error

I am getting an error

sudoku.cpp:9: error: expected initializer before âvoidâ


1
2
3
4
5
6
7
#include <iostream>

void sudoku_board(int board[])
{


}


can anyone help please
Last edited on
I use my magical powers to determine this is not your entire code, and the problem lies in what you write before that function.
is there any way you can help me fix the code to the end I know you must be busy. I wrote this sexy code to solve a sudoku puzzle I am and having difficulties as you can tell. LOL

if can help me get figured out I will really appreciate it
Last edited on
and this is still not the important part. What matters is what you have before
 
void sudoku_board(int board[])

not after it.
I removed that it works now yeah!!!!
Now I would like to call the solve function to solve the test here

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
#include "test_sudoku.h"

using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (Test_sudoku);

void Test_sudoku::solver ()
{

cout << "solve.....OK" << endl;
int puzzle[] = { 0, 1, 9, 0, 0, 2, 0, 0, 0,
				8, 0, 0, 6, 9, 0, 0, 0, 0,
				0, 5, 7, 4, 0, 0, 0, 0, 0,
				0, 0, 3, 0, 0, 0, 0, 0, 7,
				0, 0, 0, 3, 2, 5, 0, 0, 0,
				4, 0, 0, 0, 0, 0, 8, 0, 0,
				0, 0, 0, 0, 0, 8, 4, 5, 0,
				0, 0, 0, 0, 5, 3, 0, 0, 8,
				0, 0, 0, 9, 0, 0, 6, 1, 0 };
	
	solve(int puzzle[]);	
for (int i =0; i <81; i++)
		{
			cout<< puzzle[i];
		}
}



I am getting these errors

-bash-3.2$ g++ *.cpp -I/usr/local/include -L/usr/local/lib -lcppunit -ldl -g
test_sudoku.cpp: In member function âvoid Test_sudoku::solver()â:
test_sudoku.cpp:27: error: expected primary-expression before âintâ
test_sudoku.cpp:27: error: âsolveâ was not declared in this scope
-bash-3.2$
What is CPPUNIT_TEST_SUITE_REGISTRATION and what are the contents of sudoku_solver.h?
As for the "CPPUNIT_TEST_SUITE_REGISTRATION " is some googly gloppp that the professor gave us to use it used in the testing of the function.

to give you a better understanding of my code here is all of it. OK sorry about this....

this is all run on the lilux box on campus

Last edited on
sudoku.cpp and test_sudoku.cpp should both #include "sudoku.h" . (Yeah I know in test_sudoku.cpp it's redundant because you already include it in test_sudoku.h, but you shouldn't depend on that, and it doesn't hurt either cause you made sure that the preprocessor will filter out unnecessary includes either way.

Also, this (line 21 in test_sudoku.cpp)
 
solve(int puzzle[]);	


Is a function declaration. I think you want to call the function here, which you would do like this
 
solve(puzzle);
Last edited on
Thanks I did 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
////////////////////////////////////////////////////////////////////////
/// @file test_sudoku.cpp
/// @author CS 153 - A
/// @brief This file contains all the functions to test the sudoku class.
////////////////////////////////////////////////////////////////////////

#include "test_sudoku.h"
#include "sudoku.h" 
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (Test_sudoku);

void Test_sudoku::solver ()
{

cout << "solve.....OK" << endl;
int puzzle[] = { 0, 1, 9, 0, 0, 2, 0, 0, 0,
				8, 0, 0, 6, 9, 0, 0, 0, 0,
				0, 5, 7, 4, 0, 0, 0, 0, 0,
				0, 0, 3, 0, 0, 0, 0, 0, 7,
				0, 0, 0, 3, 2, 5, 0, 0, 0,
				4, 0, 0, 0, 0, 0, 8, 0, 0,
				0, 0, 0, 0, 0, 8, 4, 5, 0,
				0, 0, 0, 0, 5, 3, 0, 0, 8,
				0, 0, 0, 9, 0, 0, 6, 1, 0 };
	
	solve(puzzle);
for (int i =0; i <81; i++)
		{
			cout<< solve( puzzle[i]);	
		}
}



The following errors showed up

-bash-3.2$ g++ *.cpp -I/usr/local/include -L/usr/local/lib -lcppunit -ldl -g
test_sudoku.cpp: In member function âvoid Test_sudoku::solver()â:
test_sudoku.cpp:27: error: âsolveâ was not declared in this scope
-bash-3.2$

any other suggestions .... Pleaseeeeee
You there.....ANYONE!!!!
Well, the problem is you are trying to call a function that doesn't exist.

 
solve(puzzle);


You are trying to call a function with this signature here:
 
void solve(int something[]) //notice the something doesn't mean anything here, you would give that a different name 


In your sudoku.h you have this line:
 
//int solve(int pos) 


This is commented out, and even if it wasn't it wouldn't match the signature of the function you are trying to call.

What you have to do is to declare a function void solve(int puzzle[]) that actually solves the puzzle that it is passed.
I am confused more than ever now....sorry but, should I declare the void solve(int puzzle[]) in the test_sudoku.cpp file of the sudoku.cpp.

because I want to call it in the test.cpp file to solve the puzzle?

Sorry I think I am going to change my major LOL sorry

Any suggestion are you upset or something. I am just a beginner and its hard to know all these things and not be confused so I am trying to seek help...

Thanks for all that your doing.
Sorry I think I am going to change my major LOL sorry

You serious? That would be sad.

You should declare a void solve(int puzzle[]) in any of your two header files (I suggest sudoku.h, cause it makes more sense for it to be there) and define it in the corresponding cpp file.
Its just sooooo hard I get confused sooooo many times and there is hard any help I found this web site search for answers and here you are.

just putting void solve(int puzzle[]) will solve the problem ? Wouldn't I need to put the solve function in there

eg..

void solve(int puzzle[])
{

int board[9][9];
,,,,,,,
return 0;
}

that is what your talking about me doing..
Yeah, you need to declare void solve(int puzzle[]) in one of your header files (that is to tell your compiler that such a function exists), but you also need to define it in one of your cpp files (that is to tell your compiler what the function does).
Last edited on
As per your instructions I did what I understood, I am getting the following errors now

-
Last edited on
You are calling the function from somewhere where the compiler expects an int. However, your function returns void which is, nothing so that doesn't work.

You gotta realize, if you change a function you also have to change all the code that calls that function.

Also, please beware, I am not trying to help you do the actual program - I am just trying to tell you what the compiler errors mean, and what causes them. You yourself are responsible for making sure the program does what it's supposed to do.
Thanks I am new at this.....sorry
Topic archived. No new replies allowed.