- C++ Sudoku
- 24 May 2006 06:47:48 pm
- Last edited by Harq on 24 May 2006 07:23:06 pm; edited 1 time in total
I was incredibly bored after school today (I only had science to study for!), i decided to make a sudoku program.
Here it is
NOTE: This is not finished, i still have to finish the int main() {
section of the code, i am working on that now
Code:
OK i finished the code and for some reason, it doesn't run the disp() function at the end (display the 2d array that contains the puzzle)
OH WEL... I will finish and rewrite it after schhol is out, meanwhile i was REALLY bored so i made a program that basically does this (looks cool at the very beginning)
Code:
Now you can tell that i was REALLY bored
Here it is
NOTE: This is not finished, i still have to finish the int main() {
section of the code, i am working on that now
Code:
// This is my test program for Sudoku made in c++
// I suck at c++ and did pretty much all of it from memory
// (the debugger also helped...)
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int r,c,t,g,a;
bool i;
int grid[9][9];
int rand(int);
int check(void);
void disp(void);
int main() {
srand(time(NULL));
cout << "\n\n\n\n\n\n\n\n\n\nGenerating puzzle...";
r = 0;
while (r <= 8) {
g = 0;
c = 0;
while (c <= 8) {
disp();
return 0;
}
int rand(void) {
return rand() % 9;
}
void disp(void) {
int n,m;
for (n=0; n<=8; n++){
cout << "\n";
for (m=0; m<=8; m++) {
cout << grid[n][m] << " ";
}
}
return 0
}
int check(void) {
int n,m,p,z;
i = 0;
//Horizontal check
n = r;
for (m=0; m<=8; m++) {
if (grid[n][m] == t)
i = 1;
}
if (i)
return 0;
//Vertical check
m = c;
for (n=0; n<=8; n++) {
if (grid[n][m] == t)
i = 1;
}
if (i)
return 0;
// Square check
if (r <= 2)
n = 0;
if (r >= 3 and r <= 5)
n = 3;
if (r >= 6)
n = 6;
if (c <= 2)
m = 0;
if (c >= 3 and c <= 5)
m = 3;
if (c >= 6)
m = 6;
p = m + 3;
for (z = 0; z <= 8; z++) {
if (grid[n][m]== t)
i = 1;
m++;
if (m == p) {
m = m-3;
n++;
}
}
return 0
}
OK i finished the code and for some reason, it doesn't run the disp() function at the end (display the 2d array that contains the puzzle)
OH WEL... I will finish and rewrite it after schhol is out, meanwhile i was REALLY bored so i made a program that basically does this (looks cool at the very beginning)
Code:
#include <iostream>
using namespace std;
int a,b;
int main() {
cout << "\n\n\n\n\n\n\n\n\n\nEnter a number to count up to:";
cin >> a;
for (b = 0; b <= a; b++) {
cout << b << " ";
}
}
Now you can tell that i was REALLY bored