Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <ctime>
- #include <cctype>
- using namespace std;
- int main()
- {
- const int MAX_WRONG = 7;
- vector<string> WordList = { "large", "booger" };
- srand(static_cast<unsigned int>(time(0)));
- random_shuffle(WordList.begin(), WordList.end());
- const string TheWord = WordList[0];
- int wrong = 0;
- string soFar(TheWord.size(), '-');
- string used = " ";
- cout << "Welcome To Hangman\n";
- while ((wrong < MAX_WRONG) && (soFar != TheWord))
- {
- cout << "\n\nYou Have " << (MAX_WRONG - wrong);
- cout << " incorrect guesses left.\n";
- cout << "\nYou've used the following letters: \n" << used << endl;
- char guess;
- cout << "\n\n Enter you guess: ";
- cin >> guess;
- guess = toupper(guess);
- while (used.find(guess) != string::npos)
- {
- cout << "You have already guessed " << guess << endl;
- cout << "Enter your guess: ";
- cin >> guess;
- cout << "\n";
- guess = toupper(guess);
- }
- used += guess;
- if (TheWord.find(guess) != string::npos)
- {
- cout << "Correct, " << guess << " is the word\n";
- for (int i = 0; i < TheWord.length(); ++i)
- {
- if (TheWord[i] == guess)
- {
- soFar[i] = guess;
- }
- }
- }
- else
- {
- cout << "Sorry, " << guess << " isn't the word.\n";
- ++wrong;
- }
- }
- if (wrong == MAX_WRONG)
- {
- cout << "You've been hanged\n";
- }
- cout << "The word was " << TheWord << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement