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

int AnimalCategory(int); //function prototype
int CurrencyCategory(int); //function prototype
int ScienceCategory(int); // function prototype

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

        switch(Main_menu)
        {
            case 1:
            int AnimalCategory(int iAnswer);
            break;

            case 2:
            int CurrencyCategory(int iAnswer);
            break;

            case 3:
            int ScienceCategory(int iAnswer);
            break;

            case 4:
            return 0;
        }

        //function definition
        int AnimalCategory(int iAnswer);
        {
            int iAnswer = 0;
            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);

            if(iAnswer == 1)
            {
                printf("\nCorrect!\n");
            }
            else
            {
                printf("Incorrect\n");
                printf("Correct answer is Reindeer!");
            }
        }

        //function definition
        int CurrencyCategory(int iAnswer);
        {
            int iAnswer = 0;
            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);

            if(iAnswer == 2)
            printf("Correct!\n");
            else
            {
                printf("Incorrect!\n");
                printf("Correct answer is Ecuador\n");
            }
        }

        //function definition
        int ScienceCategory(int iAnswer);
        {
            int iAnswer = 0;
            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);

            if(iAnswer == 3)
            printf("Correct\n");
            else
            {
                printf("Incorrect!\n");
                printf("Correct answer is 4\n");
            }
        }

    }
}

the preceding is a code for my trivia game that basically ask questions based on the category the user selects but for some reason wont compile.Keeps giving the following error.

/home/ubuntu/workspace/fooling/ $ make trivia
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    trivia.c  -lcs50 -lm -o trivia
trivia.c:22:13: error: expected expression
            int AnimalCategory(int iAnswer);
            ^
trivia.c:26:13: error: expected expression
            int CurrencyCategory(int iAnswer);
            ^
trivia.c:30:13: error: expected expression
            int ScienceCategory(int iAnswer);
            ^
3 errors generated.

where did i go wrong?

1 Answer 1

0

The problem is the "int" that precedes each function call. In the function signature, the keyword that comes before the function name defines the type of the value to be returned by the function. When actually calling the function, the return type keyword should not be included.

Once you get past this problem, another lies in wait. Each of these functions is defined as having a return value of type int, but has no return statements. That will generate an error. You can have a return type of void, which means that nothing is returned, so no return statements are needed (and in fact, there shouldn't be any.)

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

2
  • where do i locate the check mark?
    – Jere
    Aug 31, 2016 at 6:14
  • It would be to the left of my answer.
    – Cliff B
    Aug 31, 2016 at 6:24

You must log in to answer this question.

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