Thread: hangman.c help

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    83

    hangman.c help

    hi,

    i helped write a program for my friend who's taking intro to c. it's been a while since i took the class.

    the program right now works fine except for one tiny situation which we're stuck on.

    in the program or "game," if the player makes 6 wrong guesses, then the game ends (takes the player to the menu). the problem i have is that i want to put a counter and increment it if 6 wrong guesses are made. and if the counter hits 6, then take the player to the menu. which, for the most part, i know how to do.

    the main problem i have is that i don't know where to put that counter. i tried placing it everywhere and i've been working on it all day yesterday and i'm at my desperation point.

    thanks,
    barneygumble742

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    1# include conio.h
    2# Avoid using goto! change "goto endprogram;" to "return 0;"
    3# Change the start lable to a while(1) cicle and at the end change "if(newga == 1) goto start;" to "if(newga != 1) break;" (leave the cicle).
    4# You code to read the word from the 1st user would crash if he inserts more than 15 chars. Use fgets(guessed,sizeof(guessed),stdin);
    But if you don't want the 2nd user to see the word leave the cicle how it is, add a check to verify is the's enough space in the buffer, and end when '@' is read.
    4# Add you error increment here :
    Code:
    //your code
    for(a = 0; a<= getguess; a++){
        if (guess == guessed[a]){
            progress [a] = guess;
        }
    }
    //declare at the beginnig a new var
    int main(){
        int is_char_guessed;
        /*...*/
    
    //add a check at the end of the cicle
    is_char_geuessed = 0;
    for(a = 0; a<= getguess; a++){
        if (guess == guessed[a]){
            progress [a] = guess;
            is_char_guessed = 1;
        }
    }
    if(!is_char_guessed)
         text++;
    Your code has a big problem. If user 1 inserts more than 15 chars, user2 never wins.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    83
    i'm not too worried about words with more than 15 characters.

    that's his problem. i just want the incorrect tries to be counted.

    also the only libraries i can use are ctype.h and stdio.h.

    thanks for your help.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    if you can't use conio.h the getch() symbol wont be defined... some compiler give errors.. other only warnings

Popular pages Recent additions subscribe to a feed