I'm making a Word Guess game.
RULES:
-Player1 will enter a word of any length for Player 2 to guess. [DONE]
-Player 2 will have 5 letter guesses and 5 word guesses total. [DONE]
-Ignore case; ex. If user enter 'T' display it as lower (without using toupper/tolower)[STUCK]
-If user guesses correct letter, replace dash(es) with letter, and what position; ex: "testing" and Player2 enters 'T' then output should be "You guessed the letters at 1 and 4 correct letter guess correct. You have 4 letter guesses remaining. Enter your first word guess".
PROBLEMS:
-Program doesn't ignore case [need to fix]
-If the letterguess is correct, or incorrect, count it as 1 letter guess and have them attempt their first word guess. DO not worry about a user guessing letters multiple times, just count it as a used guess.
-If I run the word: "testing" and I enter "T" it should display "You guessed the correct letter at 1 and 4. Enter word guess" / instead if I enter 'T' it displays "Wrong letter".... if I enter 't' it only reads the first t and not the fourth.
Any help appreciated. I am so close to being done, just stumped.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string word, guessword, guessletter;
string dashes = string(word.length(), '_');
int numletterguess = 5;
int numwordguess = 5;
bool gameover = false;
bool validletterguess;
bool validwordguess;
cout << "Player 1. Enter a word for Player 2 to guess: " << endl;
getline(cin, word);
dashes = string(word.length(), '_');
while (gameover == false && numletterguess > 0 && numwordguess > 0) // start game Round 1.
{
guessletter = "";
cout << "Player 2, you have " << numletterguess << " letter guesses left and " << numwordguess << " word guesses left. " << endl;
cout << "Enter your letter guess: " << endl;
cin >> guessletter; //letter guess
while (guessletter.length() != 1) // if the letter guess is more than a single letter, loop until user enters 1 letter.
{
cout << "Enter only 1 Letter. " << endl;
cout << "Try again: " << endl;
cin >> guessletter;
}
numletterguess--;
validletterguess = false;
for (int i = 0; i < word.length(); i++) //ignore case
{
if (guessletter.at(0) == word.at(i))
{
cout << "You guessed a letter correct at position " << i + 1 << " of the word" << endl;
dashes.at(i) = word.at(i);
cout << dashes << endl;
validletterguess = true;
break;
}
}
if (validletterguess == true) {
continue;
}
else {
cout << "Wrong letter guessed" << endl;
cout << "Player 2, you have " << numletterguess << " letter guesses left" << endl;
cout << "Enter your wordguess" << endl;
cin >> guessword;
if (guessword == word) {
gameover = true;
break;
}
else {
numwordguess--;
cout << "You guessed the wrong word!" << endl;
cout << "You have " << numwordguess << " guess left" << endl;
continue;
}
}
}
if (gameover == true)
{
cout << "You have beaten the game!" << endl;
}
else cout << "Game Over!" << endl;
}
|