To be honest, i'm really bad with c++ but it's required for my major. We have to make a sudoku program, that reads from a file, inputs the data into a 9 by 9 grid (of 2d array), inputs numbers till the grid is solved, then check for valid moves, and check when it is solved. I am stuck. This is what i have so far

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

class Sudoku 
{
private:
	int grid;
	bool badRow(int row);
	bool badCol(int col);
	bool badSec(int row, int col);
public:
	Sudoku()
	{
		
	}

	void getPuzzle();
	void display();
	void submitMove(); //check if valid, input move(badcol, badrow, badsec)
	bool isSolved();
};

void Sudoku::getPuzzle() {
	const int row = 9;
	const int col = 9;
	int gameData[row][col];
	ifstream inputFile;
	inputFile.open("game1.txt");
	if (!inputFile){
		cout << "Error opening file!" << endl;
	}
	else {
		//input data
		for (int i=0; i < row; i ++)
			for (int j=0; j < col; j++)
			inputFile >> gameData[row][col];
	
	}
}

void Sudoku::display() {
	
}

	


int main() 
{
	//declare/initialize variables
	Sudoku puzzle;
	puzzle.getPuzzle();

//begin solving loop
	//while (puzzle.isSolved()= false)
	//{
	//	puzzle.display();
	//	puzzle.submitMove();
	//}
	puzzle.display();
	cout << "congratulations! You have solved the puzzle." << endl;
	return (0);
}

//Read in puzzle, work to get it solved

any help or pointers would be amazing

Recommended Answers

All 5 Replies

Here's a pointer.

int y = 5;
int * x;

x = &y;
*x = 10;

How about you start by telling us what exactly you're having a problem with? Do you need help figuring out the logic?

i think i just get overwhelmed thinking about all the different things that have to connect and go on at one time. i think i have a good foundation here, i just need help filling in the blanks

Try making a flow chart.

I would like to point to you one basic thing that you might have going bad right now. It basically is the place where you are collecting the data.

The getdata() is collecting all the data from the file into a local variable.
This is bad, as the local variables will not be able to be accessed by the other functions in the class or your program.

My Suggestion to you would be to declare the gameData array as a member variable of your class And initialise the data there.

Apart from that, You should rather be very specific on where exactly are you having problems in order for us (Daniwebers) to help.

Hope this points you in the right direction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.