0

my code

#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;
        }

    }
}

latest compiler error

/home/ubuntu/workspace/fooling/ $ make trivia
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    trivia.c  -lcs50 -lm -o trivia
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2

1 Answer 1

0

The posted code didn't produce the errors shown when compiled. Having said that, there are a couple of structural problems. First, functions that are called should not be included within main, as has been done here. Move the last two closing curly braces up to before the first function to correct this.

Second, when creating a function, do not put a semicolon at the end of the signature line of the function itself. The opening curly brace should be the first thing after the closing parenthesis (not counting white space and a line feed). The semicolon is only used when putting the signature at the top of the file or in a .h file - when the signature alone is inserted in the file, without the code of the function.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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