I am writing the Sudoku game code and it is just from 1 to 3 (NOT to 9 like the ususal one) when i did right it give me the win message but when i did it wrong it also give me the win message, the first chart is to tell you the places and the second id the one to fill (you will see it after compile) and after finishing you have to enter the number -1 to see if you win or lose, here is the code.AND I CAN NOT USE ARRAYS
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- using std::cin;
- using std::cout;
- using std::endl;
- #include<cstdlib>
- #include<ctime>
- int main ()
- {
- char x1=' ';
- char x2=' ';
- char x3=' ';
- char y1=' ';
- char y2=' ';
- char y3=' ';
- char z1=' ';
- char z2=' ';
- char z3=' ';
- int face;
- srand( time(0) );
- face =1+rand() %15;
- switch (face)
- {
- 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='3';
- y2='2';
- z2='1';
- break;
- case 6:
- x2='2';
- y2='3';
- z1='1';
- break;
- case 7:
- x2='2';
- y2='1';
- z3='3';
- break;
- case 8:
- x3='1';
- y2='2';
- z3='3';
- break;
- case 9:
- x2='3';
- y2='2';
- y3='1';
- break;
- case 10:
- x1='1';
- y2='2';
- z2='3';
- break;
- case 11:
- x2='2';
- x3='1';
- z2='3';
- break;
- case 12:
- x3='3';
- y1='1';
- z1='2';
- break;
- case 13:
- x2='1';
- y1='3';
- y2='2';
- break;
- case 14:
- y1='1';
- y2='2';
- y3='3';
- break;
- case 15:
- z1='3';
- z2='2';
- z3='1';
- break;
- }
- /*
- cout<<endl;
- 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;
- */
- int q,w;
- 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 or -1 to exist: ";
- cin>>q;
- //
- if (q == -1) break;
- cout<<"\n enter the a value: ";
- 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";
- // skip the remain and strat anoth loop itertation
- 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=='1')&&(x2=='2')&&(x3=='3')
- ||(x1=='2')&&(x2=='1')&&(x3=='3')
- ||(x1=='2')&&(x2=='3')&&(x3=='1')
- ||(x1=='1')&&(x2=='3')&&(x3=='2')
- ||(x1=='3')&&(x2=='2')&&(x3=='1')
- ||(x1=='3')&&(x2=='1')&&(x3=='2')
- ||(y1=='1')&&(y2=='2')&&(y3=='3')
- ||(y1=='2')&&(y2=='1')&&(y3=='3')
- ||(y1=='2')&&(y2=='3')&&(y3=='1')
- ||(y1=='1')&&(y2=='3')&&(y3=='2')
- ||(y1=='3')&&(y2=='2')&&(y3=='1')
- ||(y1=='3')&&(y2=='1')&&(y3=='2')
- ||(z1=='1')&&(z2=='2')&&(z3=='3')
- ||(z1=='2')&&(z2=='1')&&(z3=='3')
- ||(z1=='2')&&(z2=='3')&&(z3=='1')
- ||(z1=='1')&&(z2=='3')&&(z3=='2')
- ||(z1=='3')&&(z2=='2')&&(z3=='1')
- ||(z1=='3')&&(z2=='1')&&(z3=='2'))
- /********************************/
- if((x1=='1')&&(x2=='2')&&(x3=='3')
- ||(x1=='2')&&(x2=='1')&&(x3=='3')
- ||(x1=='2')&&(x2=='3')&&(x3=='1')
- ||(x1=='1')&&(x2=='3')&&(x3=='2')
- ||(x1=='3')&&(x2=='2')&&(x3=='1')
- ||(x1=='3')&&(x2=='1')&&(x3=='2')
- ||(y1=='1')&&(y2=='2')&&(y3=='3')
- ||(y1=='2')&&(y2=='1')&&(y3=='3')
- ||(y1=='2')&&(y2=='3')&&(y3=='1')
- ||(y1=='1')&&(y2=='3')&&(y3=='2')
- ||(y1=='3')&&(y2=='2')&&(y3=='1')
- ||(y1=='3')&&(y2=='1')&&(y3=='2')
- ||(z1=='1')&&(z2=='2')&&(z3=='3')
- ||(z1=='2')&&(z2=='1')&&(z3=='3')
- ||(z1=='2')&&(z2=='3')&&(z3=='1')
- ||(z1=='1')&&(z2=='3')&&(z3=='2')
- ||(z1=='3')&&(z2=='2')&&(z3=='1')
- ||(z1=='3')&&(z2=='1')&&(z3=='2'))
- {
- if ((x1=='1')&&(y1=='2')&&(z1=='3')
- ||(x1=='2')&&(y1=='1')&&(z1=='3')
- ||(x1=='2')&&(y1=='3')&&(z1=='1')
- ||(x1=='1')&&(y1=='3')&&(z1=='2')
- ||(x1=='3')&&(y1=='2')&&(z1=='1')
- ||(x1=='3')&&(y1=='1')&&(z1=='2')
- ||(x2=='1')&&(y2=='2')&&(z2=='3')
- ||(x2=='2')&&(y2=='1')&&(z2=='3')
- ||(x2=='2')&&(y2=='3')&&(z2=='1')
- ||(x2=='1')&&(y2=='3')&&(z2=='2')
- ||(x2=='3')&&(y2=='2')&&(z2=='1')
- ||(x2=='3')&&(y2=='1')&&(z2=='2')
- ||(x3=='1')&&(y3=='2')&&(z3=='3')
- ||(x3=='2')&&(y3=='1')&&(z3=='3')
- ||(x3=='2')&&(y3=='3')&&(z3=='1')
- ||(x3=='1')&&(y3=='3')&&(z3=='2')
- ||(x3=='3')&&(y3=='2')&&(z3=='1')
- ||(x3=='3')&&(y3=='1')&&(z3=='2'))
- {
- cout<<"you win"<<endl;
- }
- else if((x1!=' ')&&(x2!=' ')&&(x3!=' ')
- ||(y1!=' ')&&(y2!=' ')&&(y3!=' ')
- ||(z1!=' ')&&(z2!=' ')&&(z3!=' '))
- {
- cout<<"you lose"<<endl;
- }
- }
- return 0;
- }
anyone can help? thank you.