Making a Hangman game without using <string> Data type

This is a discussion on Making a Hangman game without using <string> Data type within the C++ Programming forums, part of the General Programming Boards category; Ok so I need to make a Hangman game without using string data type and it needs to display the ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    12

    Making a Hangman game without using <string> Data type

    Ok so I need to make a Hangman game without using string data type
    and it needs to display the hangman as the game goes.
    such as if the guess is wrong show the gallows if wrong =2 show head on gallows, then wrong 3 show body etc.
    MY QUESTION IS: How do I start the project,
    can someone show a flowchart or a list on how the project needs to run in order so I can start the coding for it, ty.
    I made one "WITH" using the String data type:

    Code:
    #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("CAT");
        words.push_back("RABBIT");
        words.push_back("SNAKE");
        words.push_back("DOG");
    	words.push_back("PARROT");
    	words.push_back("FISH");
    	words.push_back("HEDGEHOG");
    	words.push_back("RACOON");
    	words.push_back("BEAR");
    	words.push_back("HAWK");
    	words.push_back("PIG");
    	words.push_back("LION");
    
        srand(static_cast<unsigned int>(time(0)));
        random_shuffle(words.begin(), words.end());
        const string THE_WORD = words[0];           
        int wrong = 0;                              
        string soFar(THE_WORD.size(), '-');        
        string used = "";                            
    
        cout << "Welcome to Hangman!\n";
    	cout << "  ______\n";
        cout << "  |    | \n";
    	cout<<  "  O    | \n";
    	cout<<  " [|]   | \n";
    	cout<<  " ( )   | \n";
    	cout<<  "_______| \n";
    	cout<<  "\n The Word is an animal \n";
    
    
        while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
        {
            cout << "\n\nYou have " << (MAX_WRONG - wrong);
    		cout << " 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 " << guess << endl;
                cout << "Enter your guess: ";
                cin >> guess;
                guess = toupper(guess);
            }
    
            used += guess;
    
    		// if word = a , if word = h , if word = n , if word =g, if word = m
            if (THE_WORD.find(guess) != string::npos)
            {
                cout << "That's right! " << guess << " is in the word.\n";
    
            
                for (unsigned 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've been hanged!";
    	    
        else
            cout << "\nYou guessed it!";
        
        cout << "\nThe word was " << THE_WORD << endl;
    
        return 0;
    }

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Quote Originally Posted by Blazefury5 View Post
    Ok so I need to make a Hangman game without using string data type
    and it needs to display the hangman as the game goes.
    such as if the guess is wrong show the gallows if wrong =2 show head on gallows, then wrong 3 show body etc.
    MY QUESTION IS: How do I start the project,
    can someone show a flowchart or a list on how the project needs to run in order so I can start the coding for it, ty.
    You're kidding, right? The design of any project, which is probably 60-70% of the project, includes flowcharting. I think it's your job to do the design. That's why you're taking the class.

    Quote Originally Posted by Blazefury5 View Post
    I made one "WITH" using the String data type:
    So change it from string to character array.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    Quote Originally Posted by WaltP View Post

    So change it from string to character array.
    And that's all I needed basically, although I said flowchart I was just using that as an example for someone to give me "SOME" type of feedback.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    ...though a little roundabout...I think the best idea would be to implement a string class of your own, incorporating all the used functionality ....thus leaving the working code unchanged..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with hangman game.
    By astarialexi in forum C Programming
    Replies: 8
    Last Post: 03-13-2011, 04:04 AM
  2. store string data as a short or other data type
    By robin2aj in forum C Programming
    Replies: 5
    Last Post: 04-07-2010, 11:02 AM
  3. changing a string to a 'double' data type
    By Brian_Jones in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2009, 05:59 PM
  4. how to convert char string to user defined data type
    By prdeepss in forum C Programming
    Replies: 5
    Last Post: 08-02-2009, 09:59 AM
  5. Hangman Game - Need Help!!
    By krobort in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2006, 04:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21