Thread: New problem [Beginner]

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    6

    New problem [Beginner]

    Hey, I got a new problem guys.

    I have a word jumbler, and you have get the word, anyways look at the code and you'll understand.. My problem is that:

    1. It doesn't allow you to do each of the words, it only lets you do the first word. I set up a count variable, but it doesn't work for me for some reason, I can't seem to understand why.
    2. I'd like to make sure it doesn't repeat the same words twice.
    3. And I'd like to find any way to minimize errors (in a way I could understand)

    Code:
    //Word Jumble
    
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <ctime>
    #include <limits>
    
    using namespace std;
    
    int main()
    {
    int count;
    int game;
    while ((count < 5) || (game != 1))
    {
        enum fields {WORD, HINT, NUM_FIELDS};
        const int NUM_WORDS = 5;
        const string WORDS[NUM_WORDS][NUM_FIELDS]=
        {
            {"wall", "Do you feel you're banging your head against something?"},
            {"glasses", "These might help you see the answer"},
            {"labored", "Going slowly is it?"},
            {"persistant", "Keep at it."},
            {"jumble","It's what the game is all about."}
            
        };
        
        srand(time(0));
        int choice = (rand() % NUM_WORDS);
        string theWord = WORDS[choice][WORD]; //Word to guess
        string theHint = WORDS[choice][HINT]; // Hint
    
    //NOT SURE?? MAYBE LATER IGNORE FOR NOW
    
    //    int wall, glasses, labored, persistant, jumble;
    //    if (WORDS[0][0] == WORD)
    //    wall = 1;
    //    if (WORDS[1][0] == WORD)
    //    glasses = 1;
    //    if (WORDS[2][0] == WORD)
    //    
    //    if (WORDS[3][0] == WORD)
    //    if (WORDS[4][0] == WORD)
    
        string jumble = theWord;
        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 << "\t\tWelcome to Word Jumble";
        cout << "\nUnscramble the letters to make a word.\n";
        cout << "Enter 'hint' for a hint.\n\n";
        cout << "Enter 'quit' to quit the game.\n\n";
        cout << "The jumble is: " <<jumble;
        
        string guess;
        cout<<"\n\nYour guess: ";
        cin >> guess;
        
        cout << "\n\nYour guess is: " << guess;
        
        while ((guess != theWord) & (guess != "quit"))
        {
            if (guess == "hint")
            {
                  cout << "\n\n" << theHint;
            }
            else
            cout << "\nSorry that's not it.";
            
            cout << "\n\n Your guess: ";
            cin >> guess;
            
            if (guess == theWord)
              {
              cout << "\nThat's it! You guessed it!\n\n";
              
              cout << "\nThanks for playing!.\n";
              }
        }
    char exit;
    cout << "\nType 0 to exit, type anything else to play again: ";
    cin >> exit;
    if ((exit == 0) || (count = 5))
    {
        if (count == 5)
        {
        cout << "\nYou have played already unscrambled 5 words!\n";
        cout << "Please make another payment for another game\n";
        cout << "\nPress enter to exit";
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
        cin.get();
        return 0;
        }
        else
        {
        cout << "\nPress enter to exit";
        game = 1;
        }
    }
    else
    {
    count = count++;
    };
    };
    return 0;
    }
    If you could help me with this code, I'd appreciate it.

    Thanks,
    -Vic

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    uhm that last if you sayd if count = 5 try count == 5 didnt test run but thats a possible logic error
    hooch

  3. #3
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Code:
    int count;
    int game;
    You'd better initialize these variables or you'll have garbage in there.
    Code:
    int count = 1;
    int game = 1;
    That's a great book, isn't it? I liked this program too.

    -JM

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM