0
#include <stdio.h>
#include <cs50.h>

int animalCategory(void); //function prototype
int currencyCategory(void); //function prototype
int scienceCategory(void); // function prototype

int main()
{
    int Main_menu = 0;

    {
        printf("\n\tTrivia Game\n");
        printf("1.\tAnimal question\n");
        printf("2.\tCurrency question\n");
        printf("3.\tScience question\n");
        printf("4.\tQuit\n");
        scanf("%d", &Main_menu);

        switch(Main_menu)
        {
        case 1:
            if (animalCategory() == 1)
                printf("\ncorrect!\n");
            else
            {
                printf("\nIncorrect\n");
                printf("The correct answer is Reindeer!\n");
            }

            break;
        case 2:
            if (currencyCategory() == 2)
                printf("\nCorrect!\n");
            else
            {
                printf("\nIncorrect!\n");
                printf("The correct answer is Ecuador\n");
            }

            break;
        case 3:
            if (scienceCategory() == 3)
                printf("\nCorrect!\n");
            else
            {
                printf("\nIncorrect!\n");
                printf("The correct answer is 4\n");
            }

            break;
        case 4:
            return 0;
        }

        //function definition
        int animalCategory();
        {
            int iAnswer = 0;
            system("clear");
            printf("\tAnimal Category\n");
            printf("\tWhat is the only kind of deer whose females have antlers?\n");
            printf("1.\tReindeer\n");
            printf("2.\tPringdeer\n");
            printf("3.\tUggdeer\n");
            scanf("%d", &iAnswer);

            return iAnswer;
        }

        //function definition
        int currencyCategory();
        {
            int iAnswer = 0;
            system("clear");
            printf("\n\tCurrency Category\n");
            printf("\tU.S dollar is the official currency of which latin American Nation?\n");
            printf("1.\tColombia\n");
            printf("2.\tEcuador\n");
            printf("3.\tArgentina\n");
            scanf("%d", &iAnswer);

            return iAnswer;
        }

        //function definition
        int scienceCategory();
        {
            int iAnswer = 0;
            system("clear");
            printf("\n\tScience Category\n");
            printf("How many planets in our solar system are smaller than the Earth?\n");
            printf("1.\t5\n");
            printf("2.\t6\n");
            printf("3.\t4\n");
            scanf("%d", &iAnswer);

            return iAnswer;
        }

    }
}

the compiler still keeps printing the following error

/home/ubuntu/workspace/fooling/ $ make trivia
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    trivia.c  -lcs50 -lm -o trivia
/tmp/trivia-0acc92.o: In function `main':
/home/ubuntu/workspace/fooling/trivia.c:24: undefined reference to `AnimalCategory'
/home/ubuntu/workspace/fooling/trivia.c:36: undefined reference to `CurrencyCategory'
/home/ubuntu/workspace/fooling/trivia.c:47: undefined reference to `ScienceCategory'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [trivia] Error 1
-1

It seems to me that the only mistake you have made was putting a semicolon after each function definition, like so:

//function definition
int animalCategory();
{
    // ...
}

This is incorrect, and is usually the result of copy-pasting the declaration (prototype). To fix this, simply remove the semicolon from behind the definitions.

//function definition
int animalCategory()
{
    // ...
}

Read more on declarations and definitions here.

You have also defined these functions inside main.

int main()
{
    // ...

    int animalCategory()
    {
        // ...
    }

    // ...
}

You should move them out of there.

int main()
{
    // ...
}

// ...

int animalCategory()
{
    // ...
}
| improve this answer | |
  • thats the function definition, of course there has to be a semicolon after. – Jerey Aug 31 '16 at 8:08
  • @Jerey I have updated my answer. It now includes a reference to an article on declarations and definitions. You should give it a read. I have also found another mistake in the code and have proposed a solution in the edited answer. – skreborn Aug 31 '16 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .