#include #include #include #include int checknum(const matrix answer, int row, int col, int num) {// return 1 if the randomized number can not be placed in the block //row int number=0; char letter; int limit=0,limit2=0; for(int column=0;column answer) // returns 1 if not full, -1 if full { for(int row=0;row &sudoku) { cout<<" "; for(int i=1; i<=9; i++) cout< &answer,const matrix &user) { for(int row=0;row answer(9,9,' '); int row,col,num; long stop=0;//check infinite variable int quit=0;//quits and tries again variable matrix def(9,9,' '); do{ answer=def; quit=0; for(row=0;row30){ quit=1; break; } }while(checknum(answer,row,col,num)==1); if(quit==0){ answer[row][col]=char(num+48); stop=0;} else break; } if(quit==1) break; } }while(boardfull(answer)==1); clrscr(); for(int r=0;r<9;r++){ for(int c=0;c<9;c++) cout< user(9,9,' '); int defnum=0; do{ cout<<"Choose difficulty:Easy,Medium,Hard "; cin>>ans; if(ans =='e' || ans == 'E'){ defnum=40; break;} else if(ans=='m'||ans=='M'){ defnum=35; break;} else if(ans=='h'||ans=='H'){ defnum=30; break;} } while(true); clrscr(); for(int give=1;give<=defnum;give++){ row = random(9); col = random(9); if(def[row][col]==' ') def[row][col]=answer[row][col]; else give--; } user=def; do{ clrscr(); displayboard(user); gotoxy(0,20); row = 0; col=0; cout<<"Choose what you want to do:Put or Remove"; cin>>ans; if(ans=='P'||ans=='p'){ cout<<"what row would you like?"; cin>>row; row = row-1; cout<<"what column would you like?"; cin>>col; col = col-1; cout<<"what number is being put here?"; cin>>num; if(user[row][col] == ' ') user[row][col]=char(num+48); else cout<<"sorry cant put it here"; } if(ans=='r' || ans=='R'){ cout<<"what row would you like?"; cin>>row; row = row-1; cout<<"what column would you like?"; cin>>col; col = col-1; if(def[row][col] ==' ') user[row][col]=' '; else cout<<"You cant remove this number, its here by default"; } cout<