Help::i have made a sudoku solver but it not workin
-
// :doh:hey here goes the program i have made pls help me out to find errors #include //#include #include #include #include class sudoku{ int a[9][9][10],count; public: sudoku(); void initsudoku(); void redprob(int , int); void dispsudoku(); void fillele(int , int ); void fillsudoku(); } ; sudoku::sudoku() { int i , j ,k; count=81; cout<<"constructor"; for( i=1;i<=9;i++) for ( j=1;j<=9;j++){ a[i][j][0]=99; for ( k=1;k<=9;k++) a[i][j][k]=0; a[i][j][10]=9; } } void sudoku::redprob(int i, int j ) { int k,l,temp; temp=a[i][j][0]; for ( k=1;k<=9;k++) { if (( k!=j) && (a[i][k][temp]!=99)); { a[i][k][temp] = 99; a[i][k][10]--; if(a[i][k][10]==1) fillele(i,k); } if (( k!=i)&&(a[k][j][temp]!=99)); { a[k][j][temp] = 99; a[k][j][10]--; if(a[k][j][10]==1) fillele(k,j); } } cout<<"l"<>i; cout<<"column no."; cin>>j; cout<<"enter value"; cin>>val; if ((i<=9)&&(j<=9)&&(a[i][j][val]==0)&&(count<=0)) { a[i][j][0]=val; a[i][j][10]=0; count--; redprob(i,j); } else if (i>9) cout<<"wrong row value"; else if (j>9) cout<<"wrong column value"; else if (count<=0) cout<<"already 81 elements have been identified"; else cout<<" you can not place this value here"; cout<<"enter any other element "; cin>>ch; } } void sudoku::fillele(int i, int j ) { for( int k=1; k<=9;k++) if( a[i][j][k] == 0){ a[i][j][0] = k; a[i][j][10]=0; count--; redprob(i,j); } } void sudoku::dispsudoku() { int i,j; for( i=1;i<=9;i++) { for ( j=1;j<=9;j++){ if(a[j][i][0]>10){ cout<<" "; } else { cout<
-
// :doh:hey here goes the program i have made pls help me out to find errors #include //#include #include #include #include class sudoku{ int a[9][9][10],count; public: sudoku(); void initsudoku(); void redprob(int , int); void dispsudoku(); void fillele(int , int ); void fillsudoku(); } ; sudoku::sudoku() { int i , j ,k; count=81; cout<<"constructor"; for( i=1;i<=9;i++) for ( j=1;j<=9;j++){ a[i][j][0]=99; for ( k=1;k<=9;k++) a[i][j][k]=0; a[i][j][10]=9; } } void sudoku::redprob(int i, int j ) { int k,l,temp; temp=a[i][j][0]; for ( k=1;k<=9;k++) { if (( k!=j) && (a[i][k][temp]!=99)); { a[i][k][temp] = 99; a[i][k][10]--; if(a[i][k][10]==1) fillele(i,k); } if (( k!=i)&&(a[k][j][temp]!=99)); { a[k][j][temp] = 99; a[k][j][10]--; if(a[k][j][10]==1) fillele(k,j); } } cout<<"l"<>i; cout<<"column no."; cin>>j; cout<<"enter value"; cin>>val; if ((i<=9)&&(j<=9)&&(a[i][j][val]==0)&&(count<=0)) { a[i][j][0]=val; a[i][j][10]=0; count--; redprob(i,j); } else if (i>9) cout<<"wrong row value"; else if (j>9) cout<<"wrong column value"; else if (count<=0) cout<<"already 81 elements have been identified"; else cout<<" you can not place this value here"; cout<<"enter any other element "; cin>>ch; } } void sudoku::fillele(int i, int j ) { for( int k=1; k<=9;k++) if( a[i][j][k] == 0){ a[i][j][0] = k; a[i][j][10]=0; count--; redprob(i,j); } } void sudoku::dispsudoku() { int i,j; for( i=1;i<=9;i++) { for ( j=1;j<=9;j++){ if(a[j][i][0]>10){ cout<<" "; } else { cout<
keshava shukla wrote:
pls help me out to find errors
It's actually up to you to find the error(s). Narrow the problem down to just a few lines of code, and then you're bound to get lots of help. No one is going to wade through a bunch of code to find something that you should be finding.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
// :doh:hey here goes the program i have made pls help me out to find errors #include //#include #include #include #include class sudoku{ int a[9][9][10],count; public: sudoku(); void initsudoku(); void redprob(int , int); void dispsudoku(); void fillele(int , int ); void fillsudoku(); } ; sudoku::sudoku() { int i , j ,k; count=81; cout<<"constructor"; for( i=1;i<=9;i++) for ( j=1;j<=9;j++){ a[i][j][0]=99; for ( k=1;k<=9;k++) a[i][j][k]=0; a[i][j][10]=9; } } void sudoku::redprob(int i, int j ) { int k,l,temp; temp=a[i][j][0]; for ( k=1;k<=9;k++) { if (( k!=j) && (a[i][k][temp]!=99)); { a[i][k][temp] = 99; a[i][k][10]--; if(a[i][k][10]==1) fillele(i,k); } if (( k!=i)&&(a[k][j][temp]!=99)); { a[k][j][temp] = 99; a[k][j][10]--; if(a[k][j][10]==1) fillele(k,j); } } cout<<"l"<>i; cout<<"column no."; cin>>j; cout<<"enter value"; cin>>val; if ((i<=9)&&(j<=9)&&(a[i][j][val]==0)&&(count<=0)) { a[i][j][0]=val; a[i][j][10]=0; count--; redprob(i,j); } else if (i>9) cout<<"wrong row value"; else if (j>9) cout<<"wrong column value"; else if (count<=0) cout<<"already 81 elements have been identified"; else cout<<" you can not place this value here"; cout<<"enter any other element "; cin>>ch; } } void sudoku::fillele(int i, int j ) { for( int k=1; k<=9;k++) if( a[i][j][k] == 0){ a[i][j][0] = k; a[i][j][10]=0; count--; redprob(i,j); } } void sudoku::dispsudoku() { int i,j; for( i=1;i<=9;i++) { for ( j=1;j<=9;j++){ if(a[j][i][0]>10){ cout<<" "; } else { cout<
Even if you posted this properly ( checked 'ignore HTML tags' ), no-one is going to fix your program for you. Work out which bit is not doing what you expect, post a relevant code snippet and ask specific questions.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog