this is the working 3x3 sudoku but i still need to do 6x6 and 9x9. i need help please and suggestions.
<replaced code with attachment>
this is the working 3x3 sudoku but i still need to do 6x6 and 9x9. i need help please and suggestions.
<replaced code with attachment>
#include "stdafx.h"
// Sudoku Game by Archie Medrano, Dennis Selirio, and Gene Delos Santos
#include<iostream> // Header
using namespace std;
#include<cstdlib>
#include<ctime>
void instruct(int);
void start(int);
void start1(int);
void start2(int);
void mainmenu(int);
int a,b,c,d,x; //Variables
char x1=' ';
char x2=' ';
char x3=' ';
char y1=' ';
char y2=' ';
char y3=' ';
char z1=' ';
char z2=' ';
char z3=' ';
int face;
int choice,q,w;
char difficultychoice, randomdifficulty;
int main ()
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tWelcome to sudoku"<<endl<<endl; // Main Menu
cin.ignore();
system("cls");
cout<<"\t\t MAIN MENU\n"<<endl;
cout<<"[1] Instructions"<<endl;
cout<<"[2] Start Game"<<endl;
cout<<"[3] Difficulty"<<endl;
cout<<"[4] High Score"<<endl;
cout<<"[5] Exit Game"<<endl;
cout<<"\nEnter your choice number:";
cin>>choice;
if(choice==1)
{
cin.ignore();
system("cls");
instruct(a);
}
else
if(choice==2)
{
start(b);
start(c);
start(d);
rand();
}
else
if(choice==3)
{
cin.ignore();
system("cls");
cout<<"\t\t\t\t Difficulty Setting"<<endl;
cout<<"\n[E] or [e] Easy\n";
cout<<"\n[A] or [a] Average\n";
cout<<"\n[H] or [h] Hard\n";
cout<<"\nPlease choose your setting (This will direct you to the game):";
cin>>difficultychoice;
if(difficultychoice=='e'||difficultychoice=='E')
{
start(b);
}
else if(difficultychoice=='a'||difficultychoice=='A')
{
}
else if(difficultychoice=='h'||difficultychoice=='H')
{
}
else
main();
}
else
if(choice==4)
{
cin.ignore();
system("cls");
main();
}
else
if(choice==5)
{
cin.ignore();
system("cls");
cout<<"\n\n\t\tEnd of the Game\n\n\n";
}
else
if(choice>5||choice<1)
{
cout<<"\nInvalid Choice\n";
main();
}
return 0;
}
void instruct(int a) //Function definition for Instructions
{
cout<<"\t\tInstructions"<<endl<<endl;
cout<<"The objective of the game is to complete the puzzle by entering numbers that\n";
cout<<"are not next to each other\n\n";
cout<<"When the game is started enter the cell number where you are going to put the\n";
cout<<"number.Just put the number only once in each cell. Do not put the same numbers\n";
cout<<"in the grid, or you will lose the game! Once you have entered a number in\n";
cout<<"the cell, you cannot change it anymore.\n\n";
cout<<"After completing the grid, enter '-1' to see if you win or you lose the game.";
cout<<"Do not enter -1 while the grid is not yet completed\n";
cout<<"Starting the game will give you random sudoku table\n";
cout<<"Choose from difficulty settings if you want a specific sudoku table\n";
cin.ignore();
system("cls");
main();
}
void start (int b) //function definition for Start game
{
system("cls");
srand( time(0) );
face =1+rand() %10; /* this game will switch faces randomly as you start the game*/
face =1+rand() %5;
face =1+rand() %15;
switch (face) //possible 20 faces
{
case 1:
x1='3';
x3='1';
y2='2';
break;
case 2:
x1='2';
y2='3';
z3='1';
break;
case 3:
x2='1';
y1='2';
z2='3';
break;
case 4:
x2='2';
y3='1';
z1='3';
break;
case 5:
x3='1';
y2='2';
z3='3';
break;
case 6:
x1='3';
y2='2';
break;
case 7:
x1='2';
z3='1';
break;
case 8:
y1='2';
z2='3';
break;
case 9:
x2='2';
z1='3';
break;
case 10:
x3='1';
z3='3';
break;
case 11:
x3='1';
y2='2';
break;
case 12:
y2='3';
z3='1';
break;
case 13:
x2='1';
break;
case 14:
z1='3';
break;
case 15:
y2='2';
break;
case 16:
x1='3';
x3='1';
y2='2';
break;
case 17:
x1='2';
y2='3';
z3='1';
x3='9';
break;
case 18:
x2='1';
y1='2';
z2='3';
y2='4';
break;
case 19:
x2='2';
y3='1';
z1='3';
z3='5';
break;
case 20:
x3='1';
y2='2';
z3='3';
y3='7';
break;
}
/*
cout<<endl; //CELL NUMBER OR CELL GRID STATUS
cout<<1<<"_|_"<<2<<"_|_"<<3<<endl;
cout<<4<<"_|_"<<5<<"_|_"<<6<<endl;
cout<<7<<" | "<<8<<" | "<<9<<endl;
cout<<"\n\n";
cout<<x1<<"_|_"<<x2<<"_|_"<<x3<<endl;
cout<<y1<<"_|_"<<y2<<"_|_"<<y3<<endl;
cout<<z1<<" | "<<z2<<" | "<<z3<<endl;
cout<<endl;
*/
while (true)
{
lb:
system("cls");
cout<<"Cells Numbers"<<endl;
cout<<1<<"_|_"<<2<<"_|_"<<3<<endl;
cout<<4<<"_|_"<<5<<"_|_"<<6<<endl;
cout<<7<<" | "<<8<<" | "<<9<<endl;
cout<<"\n\nGrid Status\n";
cout<<x1<<"_|_"<<x2<<"_|_"<<x3<<endl;
cout<<y1<<"_|_"<<y2<<"_|_"<<y3<<endl;
cout<<z1<<" | "<<z2<<" | "<<z3<<endl;
cout<<endl;
cout<<" enter the cell number (after all cells have been satisfied type -1): ";
cin>>q;
if (q == -1) break;
cout<<"\n enter the value (from 1-9 only): ";
cin>>w;
switch(q)
{
case 1:
if (x1 ==' ')
switch (w)
{
case 1: x1='1';break;
case 2: x1='2';break;
case 3: x1='3';break;
case 4: x1='4';break;
case 5: x1='5';break;
case 6: x1='6';break;
case 7: x1='7';break;
case 8: x1='8';break;
case 9: x1='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 2:
if (x2==' ')
switch (w)
{
case 1: x2='1';break;
case 2: x2='2';break;
case 3: x2='3';break;
case 4: x2='4';break;
case 5: x2='5';break;
case 6: x2='6';break;
case 7: x2='7';break;
case 8: x2='8';break;
case 9: x2='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 3:
if (x3==' ')
switch (w)
{
case 1: x3='1';break;
case 2: x3='2';break;
case 3: x3='3';break;
case 4: x3='4';break;
case 5: x3='5';break;
case 6: x3='6';break;
case 7: x3='7';break;
case 8: x3='8';break;
case 9: x3='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 4:
if (y1==' ')
switch (w)
{
case 1: y1='1';break;
case 2: y1='2';break;
case 3: y1='3';break;
case 4: y1='4';break;
case 5: y1='5';break;
case 6: y1='6';break;
case 7: y1='7';break;
case 8: y1='8';break;
case 9: y1='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 5:
if (y2==' ')
switch (w)
{
case 1: y2='1';break;
case 2: y2='2';break;
case 3: y2='3';break;
case 4: y2='4';break;
case 5: y2='5';break;
case 6: y2='6';break;
case 7: y2='7';break;
case 8: y2='8';break;
case 9: y2='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 6:
if (y3==' ')
switch (w)
{
case 1: y3='1';break;
case 2: y3='2';break;
case 3: y3='3';break;
case 4: y3='4';break;
case 5: y3='5';break;
case 6: y3='6';break;
case 7: y3='7';break;
case 8: y3='8';break;
case 9: y3='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 7:
if (z1==' ')
switch (w)
{
case 1: z1='1';break;
case 2: z1='2';break;
case 3: z1='3';break;
case 4: z1='4';break;
case 5: z1='5';break;
case 6: z1='6';break;
case 7: z1='7';break;
case 8: z1='8';break;
case 9: z1='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 8:
if (z2==' ')
switch (w)
{
case 1: z2='1';break;
case 2: z2='2';break;
case 3: z2='3';break;
case 4: z2='4';break;
case 5: z2='5';break;
case 6: z2='6';break;
case 7: z2='7';break;
case 8: z2='8';break;
case 9: z2='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
case 9:
if (z3==' ')
switch (w)
{
case 1: z3='1';break;
case 2: z3='2';break;
case 3: z3='3';break;
case 4: z3='4';break;
case 5: z3='5';break;
case 6: z3='6';break;
case 7: z3='7';break;
case 8: z3='8';break;
case 9: z3='9';
}
else
{
cout<<"play again";
continue;
goto lb;
}
break;
default:
continue;
goto lb;
}
system("cls");
cout<<endl;
cout<<"Cells Numbers"<<endl;
cout<<1<<"_|_"<<2<<"_|_"<<3<<endl;
cout<<4<<"_|_"<<5<<"_|_"<<6<<endl;
cout<<7<<" | "<<8<<" | "<<9<<endl;
cout<<"\n\n Grid Status";
cout<<x1<<"_|_"<<x2<<"_|_"<<x3<<endl;
cout<<y1<<"_|_"<<y2<<"_|_"<<y3<<endl;
cout<<z1<<" | "<<z2<<" | "<<z3<<endl;
cout<<endl;
}
if ((x1=='3')&&(y1=='7')&&(z1=='9') //Numbers on the grid that satisfy the condition
||(x1=='2')&&(y1=='6')&&(z1=='8')
||(x1=='6')&&(y1=='2')&&(z1=='8')
||(x1=='6')&&(y1=='8')&&(z1=='3')
||(x1=='9')&&(y1=='6')&&(z1=='4')
||(x1=='4')&&(y1=='2')&&(z1=='8')
||(x1=='5')&&(y1=='7')&&(z1=='1')
||(x1=='4')&&(y1=='5')&&(z1=='6')
||(x2=='5')&&(y2=='2')&&(z2=='4')
||(x2=='5')&&(y2=='3')&&(z2=='4')
||(x2=='1')&&(y2=='5')&&(z2=='3')
||(x2=='2')&&(y2=='5')&&(z2=='9')
||(x2=='7')&&(y2=='2')&&(z2=='8')
||(x2=='1')&&(y2=='6')&&(z2=='3')
||(x2=='8')&&(y2=='2')&&(z2=='9')
||(x1=='4')&&(y1=='7')&&(z1=='5')
||(x3=='1')&&(y3=='6')&&(z3=='8')
You need to turn the computer off and think about how to solve the problem before you confuse yourself with any more code. There is too much of it.
Here are some hints.
Each one of those hints suggests a function to test a given number:
Don't if..else every possible combination. There are too many. Use your procedures in an algorithm to test numbers until you can find a valid match or potential match.
I suspect your teacher will expect you to use some recursion to solve this problem. (If you are just doing this on your own, then I suggest you use some recursion to solve this problem.)
Hope this helps.
I cant even see the quick reply box because you posted so much code...
I just wrote a new OS and here is the code.
[500K Lines Here]
Yeah and I forgot to add
cout<<"Hello World\n";
at the beginning.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.