dimanche 21 février 2021

Problem in the result of a multiple choise quiz [duplicate]

I want to have a multiple choice quiz with 5 questions and I've written the following code(the first part the code is as follows):

/*C program to Ask a question and print the score
*/
#include <stdio.h>

/*********************************************************
*Function to ask the first question                      *
**********************************************************/
void q1(char ans, int res)
{
    puts("1)Which choice is a swing state?");
    puts("-----------------------------------------");
    puts("a)California");
    puts("b)Kansas");
    puts("c)Arkansas");
    puts("d)Florida");
    puts("------------------------------------------");
    scanf("%c", &ans);

    if (ans == 'd')
    {
        res = 1;
    }
    else if (ans != 'd')
    {
        res = 0;
    }

    if (res == 1)
    {
        printf("Your score is:%d out of 100\n", (1 / 5) * 100);
    }

    else if (res == 0)
    {
        printf("Your score is:%d out of 100\n", (0 / 5) * 100);
    }
    return;
}

/*********************************************************
*          The Main Function                              *
**********************************************************/
int main()
{
    char ans;
    int res;

    q1(ans, res);

    return 0;
}

The code is compiled flawlessly but I get the following output by Entering the right choice as well as the wrong choice:

Your score is:0 out of 100

Given that the code considers all choices as incorrect, please let me know that what am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire