Hi there, need little help on looping

Below is my code which i taken from my friend. I need a little help on looping, i wan this game not to end.I have tried some while loop but the game still quit.
I'm still a newbie, a little help from any of you guys will help me.Thanks.


#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("PEN");
words.push_back("BOOK");
words.push_back("BOTTLE");
words.push_back("CALCULATOR");
words.push_back("PLASTIC");
words.push_back("FAN");
words.push_back("TABLE");
words.push_back("CHAIR");
words.push_back("NOTEPAD");
words.push_back("PENCIL");

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 = " ";

system("color C");
cout << "\t\t==============================================="<<endl;
cout << "\t\t (+.+)-=-Welcome to hangman game-=-(+.+)"<<endl;
cout << "\t\t==============================================="<<endl;
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout << "Guess a name of thing that you use in daiy life."<<endl;
cout << "Each letter is represented in a line."<<endl;
cout << "You have to type only one letter in one try."<<endl;
cout << "You have " << MAX_WRONG << " tries to try and guess the word.."<<endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

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;

char guess;
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess);
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guessed (O.o)" << guess << endl;
cout << "Enter your guess : ";
cin >> guess;
guess = toupper(guess);
}

used += guess;

if (THE_WORD.find(guess) != 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;
}
}

if (wrong == MAX_WRONG)
cout << "\nYou lose...you've been hanged! (0.0)";
else
cout << "\nCongratz! You guessed it! (~.~)";

cout << "\nThe word was : " << THE_WORD << endl;

return 0;
}
1
2
3
4
5
6
7
8
9
10
bool is_running = true;

while (is_running)
{
    // Whatever you want to repeat

    // Whenever you want to end, use:
    is_running = false;
    break; // Depending if you want to immediately exit the loop
}
sorry to ask this, can i know in which side to put this code ?
Topic archived. No new replies allowed.