#include <stdio.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
typedef struct question_type
{
char question[200];
int response;
}
question_type;
const struct question_type question_table[10] =
{
{ "Are you happy?", TRUE },
{ "Are you sure?", TRUE },
{ "Did World War 1 end in 1942?", FALSE },
{ "Did World War 2 end in 1942?", TRUE }
};
int main(void)
{
int cnt, score;
int num_questions = 4;
char response;
score = 0;
cnt = 0;
while (cnt < 4)
{
printf(question_table[cnt].question);
printf("(Y/N)\n");
cnt++;
scanf("%c", &response);
while ( getchar() != '\n' );
response = toupper(response);
if ((response == 'Y' && question_table[cnt].response == TRUE)
|| (response == 'N' && question_table[cnt].response == FALSE))
{
printf("Correct\n");
score++;
}else{
printf("Wrong answer.\n");
}
}
printf("You got %d out of %d questions (%d %%)\n", score, num_questions,
100*score/num_questions);
return 0;
}