Undefined reference to 'Score'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Khadijah Ahmad
    New Member
    • Oct 2011
    • 1

    Undefined reference to 'Score'

    Hi, I'm making a program to let a user guess the correct sum of two die, but I keep getting an error that says "Undefined reference to 'Score'." Can someone tell me how to fix it? My code looks like this:

    Code:
    #include <stdio.h>
    #include <time.h>
    
    void main ()
    
    {
        {
        //Declare variables.
        int GameChoice, Guess, Answer, Score(Guess, Answer);
    
        //Ask user to chose a game.
        printf("Please chose a game by entering its' number:\nPlay Dice => Enter 1 \nGuess a Number => Enter 2\n");
        scanf("%d", &GameChoice);
    
        //If the User chooses to Play Dice
        {
        int DieTotal, UserGuess;
        if (GameChoice == 1)
            {
                //Let the computer select a number from 2 to 12.
                srand(time(0));
                DieTotal = 2 + rand() % 11;
    
                //Ask user to select a number between 2 and 12.
                printf("Select a number between 2 and 12: ");
                scanf("%d", &UserGuess);
    
                Score(Guess, Answer);
            }
        }
        }
    
    int Guess, Answer;
    int Score(Guess, Answer)
             {
             if (Guess == Answer)
                {
                    printf("\nYou won. The sum of the two numbers was %d.\n", Answer);
                }
    
            else (Guess != Answer);
                {
                    printf("\nYou lost. The sum of the two numbers was actually %d.\n", Answer);
                }
             }
    }
    Last edited by Meetee; Oct 10 '11, 09:39 AM. Reason: code tags added
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This code:

    Code:
    //Declare variables.
     int GameChoice, Guess, Answer, Score(Guess, Answer);
    isn't doing what you think it does. What is is doing is creating int variables. None of them are inititlaized except the last, which is a temp variable initiaized by a call to Score(Guess, Answer). Unfortunately, the compiler has not been made aware of Score as a function, so the compile fails.

    Had you coded this way:
    Code:
    //Declare variables.
     int GameChoice;
    int Guess;
    int Answer;
    int Score(Guess, Answer);
    
    Score would have been seen as a function prototype.
    Try to avoid doing multiple things in your lines of code. It does nothing but make the code harder to read.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      You have defined function Score within the body of function main. That is not allowed. Move the brace on line 46 (that terminates the body of function main) to line 32.

      Line 33 is problematical. Delete that line and instead embed the types of the arguments in line 34.

      Comment

      Working...