#include #include #include using namespace std; int main(){ int sudokuNumbers[9][9]{ {2, 5, 1, 8, 6, 3, 9, 7, 4}, {6, 3, 4, 2, 7, 9, 1, 5, 8}, {8, 9, 7, 4, 1, 5, 3, 6, 2}, {3, 1, 8, 6, 5, 2, 7, 4, 9}, {7, 4, 6, 1, 9, 8, 2, 3, 5}, {9, 2, 5, 3, 4, 7, 6, 8, 1}, {1, 7, 9, 5, 3, 4, 8, 2, 6}, {5, 8, 3, 9, 2, 6, 4, 1, 7}, {4, 6, 2, 7, 8, 1, 5, 9, 3} }; bool guessed[9][9]{ {false, false, false, false, false, false, false, false, false,}, {true, false, false, false, false, true, true, false, false}, {false, false, true, false, false, true, false, false, true}, {false, false, true, false, false, true, false, false, true}, {false, false, true, false, true, false, false, true, false}, {false, false, false, true, true, false, false, false, false}, {true, false, false, true, false, true, false, true, false}, {true, false, false, false, false, true, false, false, true}, {true, false, false, false, false, false, false, false,true} }; for(int i {0}; i < 9; i++){ for(int j {0}; j < 9; j++){ if(guessed[i][j]){ cout << sudokuNumbers[i][j]; } else{ cout << "-"; } cout << " "; } cout <<"\n"; } int row {0}; int column {0}; int guess {0}; int allright {0}; while(allright != 81){ cout << "What row is the number you want to guess?\n"; cin >> row; if (!cin) { cerr << "Sorry, not a valid number.\n"; return EXIT_FAILURE; } if (row > 9 || row < 1){ cerr << "Sorry, that number is outside of the bounds of the game.\n"; return EXIT_FAILURE; } cout << "What column is the number you want to guess?\n"; cin >> column; if (!cin) { cerr << "Sorry, not a valid number.\n"; return EXIT_FAILURE; } if (column > 9 || column < 1){ cerr << "Sorry, that number is outside of the bounds of the game.\n"; return EXIT_FAILURE; } cout << "What number would you like to guess?\n"; cin >> guess; if (!cin) { cerr << "Sorry, not a valid number.\n"; return EXIT_FAILURE; } if (guess > 9 || guess < 1){ cerr << "Sorry, that number is outside of the bounds of the game.\n"; return EXIT_FAILURE; } if(guess == sudokuNumbers[row-1][column-1]){ guessed[row-1][column-1] = true; cout << "Great job! You guessed one of the numbers!\n"; } else{ cout << "That was not the right number. Try again.\n"; } for(int i {0}; i < 9; i++){ for(int j {0}; j < 9; j++){ if(guessed[i][j]){ cout << sudokuNumbers[i][j]; } else{ cout << "-"; } cout << " "; } cout <<"\n"; } for(int i {0}; i < 9; i++){ for(int j {0}; j < 9; j++){ if(guessed[i][j]){ allright += 1; } } } } cout << "Congratulations, you solved a difficult one!"; return EXIT_SUCCESS; }