1 Replies - 885 Views - Last Post: 30 May 2009 - 10:10 PM Rate Topic: -----

#1 fk08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-May 09

sudoku in c++

Post icon  Posted 30 May 2009 - 08:40 PM

i have a problem with my c++ code ...i wrote the declaration of 2 variables which are i and j i for clumns and j for rows...but i dont know if i need a third variable and there i an if function that i cant write to tell the program if he find 2 repeated numbers in the same row or column or 9 small grids write "error"
here is the code:
#include<iostream>
using namespace std;
void main ()
{
	int tab[9][9];
	int i,int j;		//i is for les colonnes et j for les lignes.
	{
		for(i=0;i<=9;i++)
		{
			for(j=0;j<=9;j++)
			{
			}
		}
	}


	cout<<tab[0][0]<<endl;
	cout<<"5"<<endl;
	cout<<tab[1][0]<<endl;
	cout<<"3"<<endl;
}


Is This A Good Question/Topic? 0
  • +

Replies To: sudoku in c++

#2 Dantheman  Icon User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • Posts: 445
  • Joined: 27-May 09

Re: sudoku in c++

Posted 30 May 2009 - 10:10 PM

You don't know if you need a third variable, but how are we supposed to know? We are not the ones writing the code. To check if the number repeats, simply iterate through the current row and column using a for-loop. To check the square, figure out which square you're in (hint: use division). Then use 2 for loops to iterate through every item in it.

This post has been edited by Dantheman: 30 May 2009 - 10:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1