Word Jumble

I'm trying to create a Word Jumble program where the user can choose a difficulty. My code is as follows:

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//Word Jumble  
//The classic word jumble game where the player can ask for a hint. Also can
//select difficulties: Easy, Normal, or Hard.

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    
    enum fields {WORDS, HINT, NUM_FIELDS};
    enum difficulty {EASY, NORMAL, HARD};
    const int NUM_WORDS = 5;
    
    cout << "\t\t\tWelcome to Word Jumble!\n\n";
    cout << "Unscramble the letters to make the word!\n";
    cout << "Enter 'hint' for a hint!\n";
    cout << "Enter 'quit' to make your computer explode... er, I mean quit the game!\n";
    cout << "Now, choose your difficulty: \n\n";
    cout << "1. Easy\n";
    cout << "2. Normal\n";
    cout << "3. Hard\n";
    cin >> difficulty
    
    
    if (difficulty == EASY)
                   const string WORDS[NUM_WORDS][NUM_FIELDS] =
                   {
                         {"wall", "Do you feel like you're banging your head against something?"},
                         {"glasses", "These might help you see the answer."},
                         {"labored", "Going slowly. Is it?"},
                         {"persistent", "Keep at it."},
                         {"jumble", "It's what this game is all about."},
    };
    
    if (difficulty == NORMAL)
                   const string WORDS[NUM_WORDS][NUM_FIELDS] =
                   {
                         {"Humpty Dumpty", "All the king's horses, and all the king's men..."},
                         {"withdraw", "Into his shell."},
                         {"whisper", "Don't let them overhear you!"},
                         {"playing", "What you are doing now."},
                         {"emuparadise", "A good emulation site and community."},
    };
    
    if (difficulty == HARD)
                   const string WORDS[NUM_WORDS][NUM_FIELDS] =
                   {
                         {"eulogy", "Tribute to the dead."},
                         {"zealot", "Fanatic."},
                         {"vigilante", "Operating outside the law, for the law."},
                         {"tournament", "Fight to the top!"},
                         {"pharaoh", "Ancient Egyptian king."},
    };
    
    srand(time(0));
    int choice = (rand() % NUM_WORDS);
    string theWORD = WORDS[choice][WORD]; //word to guess
    string theHINT = WORDS[choice][HINT]; //hint to word
    
    string jumble = theWORD; //jumbled version of 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 << "The jumble is: " << jumble;
    
    string guess;
    cout << "\n\nYour guess: ";
    cin >> guess;
    
    while ((guess != theWORD) && (guess != "quit"))
    {
          if (guess == "hint")
             cout << theHINT;
          else 
             cout << "Sorry, that's not correct.";
             
          cout << "\n\nYour guess: ";
          cin >> guess;
    }
    
    if (guess == theWORD)
       cout << "\nThat's correct! You've won!\n";
       cout << "\nThanks for playing!\n";
       
       
    cout << "\n\nPress enter to exit.";
    cin.get();
    return 0;
}


I don't know what's causing it to not work. I've even asked a pal, but he can't figure out what I'm doing wrong either (though on his end he's getting syntax errors on the if and while portions). Here's the uploaded .cpp file if it could help somebody figure out my issues: http://www.megaupload.com/?d=I9SZ4WVY (sorry if I'm not supposed to link or code links like this, I'm used to another forum so it's a habit now).

Any help would be appreciated.
Last edited on
I don't know if this will fix, but -
if (difficulty = EASY) if (difficulty = NORMAL) if (difficulty = HARD)

Equality . Symbol .
Gah, I don't know how I missed that. Fixing that didn't do anything though, I'm still getting the same number of errors. Here's what they are:

Line 30: Expected primary expression before "if"
Line 30: Expected ';' before "if"
Line 50: Expected primary expression before "==" token
Line 50: Expected primary expression before "==" token
Line 60: Invalid types 'main()::fields[int]' for array subscript
Line 60: Invalid types 'main()::fields[int]' for array subscript

Thanks for pointing that out though bluezor.
Last edited on
You are missing a semi-colon on line 27.
difficulty is not a variable, but a (enum) type, make a variable with type difficulty.
I was told on another forum that I really screwed up the content of the if statements, so I think I'll put this on hold until I've learned more. Thanks for all the help though :)
Topic archived. No new replies allowed.