// Program: Wheel of Fortune // // This program simulates a very simple, single-word version // of the Wheel of Fortune program seen on television. The // player guesses successive letters in an attempt to, as soon // as possible, guess the hidden puzzle word. #include #include using namespace std; // A description of each of the functions you are to write is // contained in that function's definition found following the end // of the main program. void setUpTheBoard(string &displayBoard, string puzzleAnswer); void setUpUsedLetterBoard(string &usedLetterBoard); string getThePuzzleWord(); char getLetterGuessFromPlayer(); string getWordGuessFromPlayer(); void turnMatchingLetters(string puzzleAnswer, string &displayBoard, char letter); void updateUsedLetterBoard(string &ULB, char letter); void printBoard(string displayBoard); char upperCaseLetter(char letter); string upperCaseWord(string wordIn); int main() { string puzzleWord, board, letterBoard; // Get the puzzle solution from Pat Sajak puzzleWord = getThePuzzleWord(); // Initialize the letter blocks which Vanna turns with all _'s setUpTheBoard(board, puzzleWord); // Initialize the used letter board with the letters A...Z // As a letter is guessed it will be *'ed out setUpUsedLetterBoard(letterBoard); bool gameWon=false; // Play the game until it is won (i.e until gameWon==true) while (!gameWon) { char letterGuess; // Get the first letter guess from the player letterGuess = getLetterGuessFromPlayer(); // Update the board by inserting matching letters where they belong // puzzleWord holds the solution/answer. Board holds/shows the // correct letters the player has guessed. letterGuess is the // letter which the player has just guessed and you are comparing // against the solution in puzzleWord to determine which (if any) // letters to turn over in board. turnMatchingLetters(puzzleWord, board, letterGuess); // Mark off with an * the letter which is guessed (on the used letter board) updateUsedLetterBoard(letterBoard, letterGuess); // Print out the used letter board so the player can see which letters have // already been chosen before. printBoard(letterBoard); cout << endl; // Print out the board of correctly guessed letters // which Vanna has turned over so far printBoard(board); cout << endl << endl; string puzzleGuess; char yOrN; // Ask if the player wants to guess the puzzle cout << "Do you want to guess the puzzle? (Y/N)"; cin >> yOrN; yOrN = upperCaseLetter(yOrN); // Get the guess from the player if they want to guess the puzzle if (yOrN == 'Y') { puzzleGuess = getWordGuessFromPlayer(); // Tell the player when their guess was incorrect. if (puzzleGuess != puzzleWord) cout << "Incorrect. Keep trying. " << endl; } // Set the 'flag' (gameWon) to true to stop the game if the player // guessed the puzzle correctly or just guessed the last letter correctly. if ((board == puzzleWord) || (puzzleGuess == puzzleWord)) gameWon = true; } // Congratulate the player on win. cout << "Congratulations. You guessed the word." << endl; return 0; } // end main // You are provided the following function setUpTheBoard // ***************************************************************** void setUpTheBoard(string &displayBoard, string puzzleAnswer) { // This function puts an '_' (underscore // character) in all positions of the display board. // (Like the blank letters shown before Vanna // turns them around.) for (int i = 0; i