Thread: Hangman program

  1. #1
    Registered User
    Join Date
    Nov 2001

    Question Hangman program

    I have to create a program that asks the user for a word clears the screen then lets the user guess the letters or the whole word so far i have it so that is clears the screen after the word is entered and if you want to guess the whole word you can, the problem is I dont know what to do with guessing single letters
    this is what i have so far:

    int main()
    char secret[100];
    char answer;
    char answer2[100];
    cout<<"Enter word: "<<endl;
    for(int i=0; i<secret.length(); i++)
    cout<<"Enter your guess($ to guess the whole word and * to quit): "<<endl;
    	cout<<"Enter your guess for the whole word: ";
    	if(strcmp(secret, answer2))
    		cout<<"incorret, guess again"<<endl;
    		cout<<"You are right!";
    I need to make the output something like
    I also wanted to use secret.length(); to print the intial dashs of how long the word was but I cant get it to work

    Any help is apprieciated
    thank you
    I am a C++ newb
    using: Visual C++ 6.0
    thanx for any Help

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    char isn't a class and doesn't have a length() member function

    You probably want string. Include <string> and use the standard namespace.

    And instead of using strcmp, just use == (overloaded operator found in the string class)

    To find if it's in your string... just go from position 0 to the end of the string is see if your char matches any place... if it does... use some sort of gotoxy() to place that char on the screen

    You can do it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Hangman program
    By Trank07 in forum C Programming
    Replies: 1
    Last Post: 11-24-2007, 10:00 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Help on hangman program
    By vserenev in forum C++ Programming
    Replies: 1
    Last Post: 01-11-2007, 12:34 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM