been working on this code for 2-3 hours using the basic c++ information. tearing out my hair trying to figure out what is wrong writing hangman programm but trying to use functions to initialize programm and enter and response computer saying little or no error but wont launch can't figure out what to do plz help me. there are two types ive tried
OPTION 1:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype>
using namespace std;
char getGuess();
string inWord();
int main()
{
// set-up
const int MAX_WRONG = 8;
vector<string> words;
words.push_back("GUESS");
words.push_back("HANGMAN");
words.push_back("DIFFICULT");
srand(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!!";
}char getGuess()
{
char guess;
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess);
return guess;
}
string inWord()
{
vector<string> words;
char guess;
const string THE_WORD = words[0];
char guess1 = THE_WORD.find(guess);
int wrong = 0;
string soFar(THE_WORD.size(), '-');
if (guess1 != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
for (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;
}
return soFar;
}
while ((wrong < MAX_WRONG) && (soFar != THE_WORD));
{
cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n" << used << endl;
cout << "\nSo far, the word is:\n" << soFar << endl;
getGuess()
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guessed " << guess << endl;
cout << "Enter your guess: ";
cin >> guess;
guess = toupper(guess);
}
used += guess;
inWord()
// shut down
if (wrong == MAX_WRONG)
cout << "\nYou've been hanged!";
else
cout << "\nYou guessed it!";
cout << "\nThe word was " << THE_WORD << endl;
return 0;
}
OPTION 2:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype>
using namespace std;
char getGuess();
string inWord();
int main()
{
const int MAX_WRONG = 8;
char guess;
vector<string> words;
words.push_back("GUESS");
words.push_back("HANGMAN");
words.push_back("DIFFICULT");
srand(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!!";
while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
{
cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n" << used << endl;
cout << "\nSo far, the word is:\n" << soFar << endl;
getGuess();
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guessed " << guess << endl;
cout << "Enter your guess: ";
cin >> guess;
guess = toupper(guess);
}
used += guess;
inWord();
if (wrong == MAX_WRONG)
cout << "\nYou've been hanged!";
else
cout << "\nYou guessed it!";
cout << "\nThe word was " << THE_WORD << endl;
return 0;
}
}
char getGuess()
{
char guess;
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess);
return guess;
}
string inWord()
{
vector<string> words;
char guess;
const string THE_WORD = words[0];
char guess1 = THE_WORD.find(guess);
int wrong = 0;
string soFar(THE_WORD.size(), '-');
if (guess1 != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
for (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;
}
return soFar;
}