Ok so I need to make a Hangman game without using string data type
and it needs to display the hangman as the game goes.
such as if the guess is wrong show the gallows if wrong =2 show head on gallows, then wrong 3 show body etc.
MY QUESTION IS: How do I start the project,
can someone show a flowchart or a list on how the project needs to run in order so I can start the coding for it, ty.
I made one "WITH" using the String data type:
Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype>
using namespace std;
int main()
{
const int MAX_WRONG = 8;
vector<string> words;
words.push_back("CAT");
words.push_back("RABBIT");
words.push_back("SNAKE");
words.push_back("DOG");
words.push_back("PARROT");
words.push_back("FISH");
words.push_back("HEDGEHOG");
words.push_back("RACOON");
words.push_back("BEAR");
words.push_back("HAWK");
words.push_back("PIG");
words.push_back("LION");
srand(static_cast<unsigned int>(time(0)));
random_shuffle(words.begin(), words.end());
const string THE_WORD = words[0];
int wrong = 0;
string soFar(THE_WORD.size(), '-');
string used = "";
cout << "Welcome to Hangman!\n";
cout << " ______\n";
cout << " | | \n";
cout<< " O | \n";
cout<< " [|] | \n";
cout<< " ( ) | \n";
cout<< "_______| \n";
cout<< "\n The Word is an animal \n";
while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
{
cout << "\n\nYou have " << (MAX_WRONG - wrong);
cout << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n" << used << endl;
cout << "\nSo far, the word is:\n" << soFar << endl;
char guess;
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess);
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guessed " << guess << endl;
cout << "Enter your guess: ";
cin >> guess;
guess = toupper(guess);
}
used += guess;
// if word = a , if word = h , if word = n , if word =g, if word = m
if (THE_WORD.find(guess) != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
for (unsigned int i = 0; i < THE_WORD.length(); ++i)
{
if (THE_WORD[i] == guess)
{
soFar[i] = guess;
}
}
}
else
{
cout << "Sorry, " << guess << " isn't in the word.\n";
++wrong;
}
}
if (wrong == MAX_WRONG)
cout << "\nYou've been hanged!";
else
cout << "\nYou guessed it!";
cout << "\nThe word was " << THE_WORD << endl;
return 0;
}