I wanted it to be fully editable.
You can add your own, words, using function words.push_back("Your Word");
(in case didnt know).
thanks for having a look.
Please report any bugs.
Written by-
CyberSpy aka TheFutureOfEminem
- Code: Select all
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
int main()
{
const int MAX_WRONG=8;
vector<string> words;
words.push_back("school");
words.push_back("computer");
words.push_back("cheat");
words.push_back("lose");
words.push_back("yourself");
words.push_back("they");
words.push_back("dont");
words.push_back("care");
words.push_back("about");
words.push_back("us");
words.push_back("hunter");
words.push_back("thriller");
words.push_back("billie");
words.push_back("jean");
words.push_back("sing");
words.push_back("for");
words.push_back("the");
words.push_back("moment");
words.push_back("fraction");
words.push_back("geography");
words.push_back("dangerous");
words.push_back("documentation");
words.push_back("vector");
words.push_back("hello");
srand(time(0));
random_shuffle(words.begin(), words.end());
const string theWord=words[0]; //Word To Be Guessed
int wrong=0;
string soFar(theWord.size(), '-');
string used=" ";
cout<<" Welcome To Hangman\n"<<endl;
while((soFar!=theWord) && (wrong<=MAX_WRONG))
{
char guess;
cout<<"You have "<<MAX_WRONG-wrong <<" chances left.\n";
cout<<"So far the word is \n"<< soFar;
cout<<"\nEnter your guess : ";
cin>>guess;
while(used.find(guess)!=string::npos)
{
cout<<"\nYou have already guessed that character";
cout<<"\nEnter another letter : ";
cin>>guess;
}
used+=guess;
if(theWord.find(guess)!=string::npos)
{
cout<<"\nCorrect the letter is in the word\n";
for (unsigned int i=0; i<=theWord.length();i++)
{
if(theWord[i]==guess)
{
soFar[i]=guess;
}
}
}
else
{
cout<<"\nThe guess is incorrect.\n";
wrong++;
}
}
if(wrong==MAX_WRONG)
cout<<"\nYou have been hanged\n";
else
cout<<"\nCongratulations, you guessed it!!!\n";
cout<<"\nThe word was "<<theWord<<endl;
cout<<"\n\n Written By-\n CyberSpy aka TheFutureOfEminem\n";
return 0;
}
