what am i doing wrong

I can't figure out why this code isn't working that I have put together when ever I put in the answer it just stops write there and the while loop it's working properly either any help would be appreciated.



// Word Jumble
// 11/02/2012



#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()

{

enum fields {word, hint, num_fields};
const int num_words =5;
const string words[num_words][num_fields]=

{
{"fall","have a nice trip see you next???"},
{"fart","something that stinks"},
{"dart","something you throw at a bar."},
{"art","leonardo,mikey,donatello,ralph"},
{"batman","joker"}
};

srand(static_cast<unsigned int> (time(0)));
int choice = (rand()% num_words);
string theword = words[choice][word];//word to guess
string thehint= words[choice][hint];//hint for the word

string jumble = theword; //jumbled version of the word
int length = jumble.size();
for (int i=0; i < length; i++)
{
int index1= (rand() % length);
int index2= (rand() % length);
char temp = jumble[index1];
jumble[index1]= jumble[index2];
jumble[index2]= temp;
}

cout << "Welcome to the Word Jumble Playing game"<< endl;
cout << "Can you unscramble the words?" << endl;
cout << "If you need help to figure the word out enter in 'hint'!" <<endl;
cout << "If you can't figure it enter in 'quit'" << endl;
cout << "The jumbled word is going to be!!!!" << jumble << endl;

string guess;
cout << "What is your guess going to be!!!" << endl;
cin >> guess;
int yes;
while (guess !="quit");{
if (guess == "hint")
{
cout << thehint;

}

if (guess==theword)
{
cout << "YOU GOT IT!!! would you like to try another word???" << endl;
string yes;

if (guess== yes)
{
cin >> guess;
cout << "the new word is:" << jumble << endl;
}
}
}
return 0;
system("pause");
}

Use code tags (the <> button on the right).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Word Jumble
// 11/02/2012



#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()

{

enum fields {word, hint, num_fields};
const int num_words =5;
const string words[num_words][num_fields]=

{
{"fall","have a nice trip see you next???"},
{"fart","something that stinks"},
{"dart","something you throw at a bar."},
{"art","leonardo,mikey,donatello,ralph"},
{"batman","joker"}
};

srand(static_cast<unsigned int> (time(0)));
int choice = (rand()% num_words);
string theword = words[choice][word];//word to guess
string thehint= words[choice][hint];//hint for the word

string jumble = theword; //jumbled version of the word
int length = jumble.size();
for (int i=0; i < length; i++)
{
int index1= (rand() % length);
int index2= (rand() % length);
char temp = jumble[index1];
jumble[index1]= jumble[index2];
jumble[index2]= temp;
}

cout << "Welcome to the Word Jumble Playing game"<< endl;
cout << "Can you unscramble the words?" << endl;
cout << "If you need help to figure the word out enter in 'hint'!" <<endl;
cout << "If you can't figure it enter in 'quit'" << endl;
cout << "The jumbled word is going to be!!!!" << jumble << endl;

string guess;
cout << "What is your guess going to be!!!" << endl;
cin >> guess;
int yes;
while (guess !="quit");{
if (guess == "hint")
{
cout << thehint;

}

if (guess==theword)
{
cout << "YOU GOT IT!!! would you like to try another word???" << endl;
string yes;

if (guess== yes)
{
cin >> guess;
cout << "the new word is:" << jumble << endl;
}
}
}
return 0;
system("pause");
}


Get rid of the semicolon on line 53. It's making the while loop run indefinitely.
Topic archived. No new replies allowed.