Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make a program, which a bot will quiz us?

0 votes
asked Nov 24, 2020 by Superman365 (560 points)

Can we make a bot quiz us? How to scan, and reply to us is it wrong/correct?smiley

2 Answers

+1 vote
answered Nov 24, 2020 by Superman365 (560 points)

I don't know how to make a quiz botsad

commented Nov 24, 2020 by Superman365 (560 points)
Really Bad. It is really bad to not know
0 votes
answered Nov 25, 2020 by Peter Minarik (84,720 points)
edited Nov 25, 2020 by Peter Minarik

Start Simple

You can start with something simple as below and upgrade it along the way:

#include <stdio.h>
#include <string.h>

int main()
{
    char capital[100];
    printf("What is the capital of Switzerland? : ");
    scanf("%s", capital);
    if (strcmp(capital, "Bern") == 0)
    {
        printf("Correct.\n");
    }
    else
    {
        printf("Wrong.\n");
    }

    return 0;
}

Generalise

You can make the whole process generic easily by creating an array of quiz and asking and evaluating each one of these quiz questions.
#include <stdio.h>
#include <string.h>

#define ArrayLength(array) (sizeof(array) / sizeof(array[0]))

typedef struct
{
    const char * question;
    const char * answer;
} Quiz;

static void AskQuiz(const Quiz * quiz)
{
    char answer[100];
    printf("%s : ", quiz->question);
    scanf("%s", answer);
    if (strcmp(answer, quiz->answer) == 0)
    {
        printf("Correct.\n\n");
    }
    else
    {
        printf("Wrong.\n\n");
    }
}

int main()
{
    Quiz quiz[] =
    {
        { "What is the capital of Switzerland?", "Bern" },
        { "What year did World War 2 start?", "1939" },
        { "How high is the highest mountain on Earth (in meters)?", "8848" },
    };
    
    int count = ArrayLength(quiz);
    
    for (int i = 0; i < count; i++)
    {
        AskQuiz(&quiz[i]);
    }

    return 0;
}
commented Nov 25, 2020 by Superman365 (560 points)
Thanks for the answer
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...