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 
	int grid;
	bool badRow(int row);
	bool badCol(int col);
	bool badSec(int row, int col);

	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;
	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;

//begin solving loop
	//while (puzzle.isSolved()= false)
	//	puzzle.display();
	//	puzzle.submitMove();
	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

6 Years
Discussion Span
Last Post by Sky Diploma

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


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.