Thread: Need help with letter guessing program

  1. #16
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    Can anyone please help i need to get this finished

  2. #17
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Post your code with the errors...

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I've already given you your best advice. The time you've been wasting here trying to beg for more help you could have used to do what I said, and have been done by now.

    Break your program into small steps. Test each one. Combine them one at a time into a bigger program, testing as you do. There are no steps to skip there. Do it right, or don't do it at all. You don't even have to put them in their own program, but you do have to do them one at a time and test each one. There are no free passes in programming. You think about your problem, break it into steps, and test each step after you've written it before moving to the next one. Because if you do it any other way than that, it's way more work in the long run.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    I think i did the part good this time, but i got some dumb errors. it has missing ';' before 'type' on the side of int games and it now says numguesses is undeclared seriously what the hell?

    Code:
    #define _CRT_SECURE_NO_DEPRECATE
    #include <stdio.h>
    #define MAXGUESSES 6
    
    
    void Instructions( );
    
    
    int PlayGame(char answer);
    
    
    char  GetGuess(  );
    
    
    int CompareGuess(char guess, char answer);
    
    
    int main()
    {
        //declare additional variables
    char letter=0;
    int gamesToPlay = 0;
    int i = 0;
    FILE *inp;
    Instructions();
    inp=fopen("guessLtrs.txt","r");
    scanf(" %d",&gamesToPlay);
    //get c letter
    
    
        
        //open file
        //get number of games to play
        
        
    
        for(i=0;i<gamesToPlay;i++)
        {
    fscanf(inp," %c",&letter);
    GetGuess(  );
    
    
            //get a letter from file
            //Play one game
            //check for win or lose    
        }
        fclose(inp);
        //close file
        return 0;
    }
    
    //this function provides instructions to the user on how to play the game
    void Instructions( )
    {
    printf("Welcome to Letter Guess\n");
    printf("To begin you will enter the number of games you want to play(1 – 5 games)\n");
    printf("You have 6 chances to guess each letter\n");
    printf("Let's begin:\n\nHow many games would you like to play? (1 - 5):");
    return;
    }
    
    //this function prompts the player to make a guess and returns that guess
    //this function is called from inside the PlayGame( ) function described above
    
    char  GetGuess(  )
    {
        char guess=0;
    printf("Enter a guess:", guess);
    scanf(" %c",&guess);
    return guess;
    }
    
    //this function takes two arguments, the guess from the player and the answer from the file. 
    //It lets the user know if the guess comes alphabetically before or after the answer 
    //The function returns 1 if the guess matches the answer and returns a 0 if they do not match
    
    int CompareGuess(char guess, char answer)
    {
        if (guess==answer)
    return 1;
    else
    if (guess<answer){
    printf("The letter you are trying to guess comes after %c", guess);
    return 0;
    }else{
    printf("The letter you are trying to guess comes before %c", guess);
    return 0;
    
    
    }
    //this function runs one game. It for checks either 6 incorrect guesses or correct guess.
    //It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
    
    int PlayGame(char answer)
    {    
        int numGuesses = 0;
        while(numGuesses < MAXGUESSES)
        {    
            GetGuess(  );
    
            //get guess function call
    //compare guess function call
    //update counter for number of guesses used
    numGuesses = numGuesses +1;
        }
        
    }
    i am making progress but it's super slow.

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by ltdec View Post
    I think i did the part good this time, but i got some dumb errors. it has missing ';' before 'type' on the side of int games and it now says numguesses is undeclared seriously what the hell?
    Those errors your compiler spits out at you conveniently have line numbers. I wonder if you could use that somehow to figure out what line the error was on?

    Oh, and you never actually use what GetGuess returns, so there's not really any point in even having that function.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #21
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    I know what lines the errors are on, but i see no way in fixing them
    where am i supposed to put a ( in int PlayGame(char answer) i sure as hell know you don't put it on the end.

    As for numguesses it has already been declared why is it sayin it is undeclared?


    What do i do with getGuess then? it says i have to function call it into int playgame.
    Last edited by ltdec; 10-04-2011 at 08:20 PM.

  7. #22
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    You never call compareGuess or PlayGame. START SMALL...Post your code with only your main and getGuess functions. Then print the guess in main after calling getGuess. If you can't do that I don't think there is much more help we can give you. You will need to go back and learn the basics.

  8. #23
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    If I never call compare guess or playgame why does the outline tell me to put the functions into Int Playgame?

  9. #24
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    What I'm saying is you never use that function...

  10. #25
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    Can you explain step by step i'm new to all of this.

  11. #26
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You aren't even trying to solve this. You are just throwing code around and hoping it happens to work right. Programming doesn't typically work that way. You actually are required to think out and plan what you want to do. There are very very few people who can successfully sit down and just start writing programs from start to finish without having to stop and ponder what they want to do.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #27
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    I was good until this compare and greater than became involved also this is the biggest program to date i've had to do. I did not think it would be that difficult when i first started but i was dead wrong. I wont ask for help after this program I promise, Im gonna have to devote a good amount of time into programming.

  13. #28
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    can you explain how to solve those errors? even if i remove the getguess function i still get them.

  14. #29
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Start with this...

    Now send guess and letter to the compareGuess function and see if they are the same. Once you can do that let us know.

    Code:
    #include <stdio.h>
    
    void getGuess(char* guess);
    
    int main()
    {
        char guess;
        char letter = 'R';
     
        getGuess(&guess);
        printf("%c\n",guess);
        //call compareGuess
    
        return 0;
    }
    
    void getGuess(char* guess)
    {    
        printf("Enter a char: ");
        scanf("%c",guess);    
    }

  15. #30
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    He can't understand returning a value so you want him to use pointers? Him and the tic-tac-toe guy need to get together. :rofl:


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with program exercise -- Guessing counter
    By NinjaFish in forum C Programming
    Replies: 8
    Last Post: 04-02-2011, 10:50 AM
  2. Guessing program Hm. Help
    By snugy in forum C Programming
    Replies: 3
    Last Post: 11-17-2008, 11:09 AM
  3. help with guessing game program
    By dc0n in forum C++ Programming
    Replies: 13
    Last Post: 02-07-2006, 08:15 PM
  4. Guessing Program
    By webren in forum C++ Programming
    Replies: 6
    Last Post: 04-10-2005, 07:24 PM
  5. need help with a guessing game program
    By davidnj732 in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2003, 11:59 AM