Thread: Help Me

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    1

    Question Help Me

    I am a begginner programmer, and i'm just trying to make a simple guessing game. Whats wrong with my code?



    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>


    int guess(void);
    int answer(void);
    int main( void )
    {
    printf ( "Guessing Game!\n\n\n\n\n" );
    printf ( "You Have 5 guesses.....GO\n\n\n\n " );
    guess();
    return 0;
    }

    guess()
    {

    srand( clock() );

    answer = answer;

    scanf ( "%s", guess );
    if (guess > answer)
    printf ("Too high, Guess Again!\n\n");
    else
    if (guess < answer)
    printf ("Too low, Guess Again!\n\n");
    else
    printf ("You've got it! Good Job");

    scanf ("%s", guess);
    if (guess > answer)
    printf ("Too high, Guess Again!\n\n");
    else
    if (guess < answer)
    printf ("Too low, Guess Again!\n\n");
    else
    printf ("You've got it! Good Job");
    scanf ("%s", guess);
    if (guess > answer)
    printf ("Too high, You Loose, the answer was %d!\n\n", answer);
    else
    if (guess < answer)
    printf ("Too low, You Loose, the answer was %d!\n\n", answer);
    else
    printf ("You've got it! Good Job");
    return 0;}

    int answer(void)
    {
    return (rand() % 100);





    }








    Thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    First up, it's not in code tags.

    You should only call srand() once during a programs execution.

    This is incorrect:
    >>answer = answer;
    maybe you meant:
    >>int myanswer = answer();
    also, guess is a function name, so you need a variable to trap the users response:
    >>int usersguess;
    >>scanf ("%d", &usersguess);

    then you go:
    >>if (usersguess > myanswer)
    etc

    I suggest you read:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed