Question
PLEASE HELP Mr. Coleman teaches second grade at Hinesbrook. On days when the weather is bad and the students cannot go outside to play, he
PLEASE HELP
Mr. Coleman teaches second grade at Hinesbrook. On days when the weather is bad and the students cannot go outside to play, he spends recess time playing a simplified version of the hangman game with his class. Thegame requires two people to play. Currently, Mr. Coleman think of a word that has five letters.He then draws five dashes on the chalkboard--one for each letter in the word. One student then is chosen to guess the word, letter by letter. When the student guesses a correct letter, Mr. Coleman reeplaces the appropriate dash or dashes with the letter. For example, if the original word is moose and the student guesses the letter o, Mr. Coleman changes the five dashes on the chalkboard to -oo-. The game is over when the student either guessess all of the letters in the word or makes 10 incorrect guessess, whichever occurs first. Mr. Coleman wants a program that allows two students to play the game on the computer.
Chapter 13, Lab 13-2
//Lab13-2.cpp - Guess the Word game
#include#include #include #include using std::cout; using std::cin; using std::endl; using std::string; int main() { //declare variables string letters = "abcdefghijklmnopqrstuvwxyz"; string randomLetter = ""; string guess = ""; int length = 0; int x = 0; int randomNumber = 0; //generate random letter srand(int(time(0))); randomNumber = 1 + rand() % (26 - 1 + 1); randomLetter = letters.substr(randomNumber, 1); cout << randomLetter << endl; //get the user's guess while (length = 1) { cout << "Enter your guess: "; getline(cin, guess); //validate input length = guess.length(); if (length != 1) { cout << "Your guess is not exactly one letter" << endl; return 0; } transform(guess.begin(), guess.end(), guess.begin(), tolower); x = guess.compare(0, 1, randomLetter); if (x = 0) { cout << "You guessed the correct number" << endl; } else if (x = -1) { cout << "The correct letter comes after the letter" << endl; } else { cout << "The correct letter comes before the letter" << endl; } } return 0; } //end of main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started