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