You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.5 KiB
92 lines
2.5 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
#include "timequiz.h"
|
|
|
|
void timequiz();
|
|
|
|
int getRandomQuestionIndex(int askedQuestions[], int totalQuestions);
|
|
|
|
void displayQuestion(char* question, char* answers[], int correctIndex);
|
|
|
|
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers, char* answers[]);
|
|
|
|
void timequiz() {
|
|
|
|
printf("Welcome to our Time Quiz!\n");
|
|
printf("You have 60 seconds to answer the questions. Have fun!\n");
|
|
|
|
char* questions[] = {
|
|
"What is the capital of France?",
|
|
};
|
|
|
|
char* answers[][4] = {
|
|
{"Paris", "London", "Berlin", "Madrid"},
|
|
};
|
|
|
|
int correctAnswers[] = { 1 };
|
|
|
|
for (int i = 0; i < sizeof(questions) / sizeof(questions[0]); i++) {
|
|
int j = rand() % 4;
|
|
char* temp = answers[i][0];
|
|
answers[i][0] = answers[i][j];
|
|
answers[i][j] = temp;
|
|
|
|
if (j == 0) {
|
|
correctAnswers[i] = 1;
|
|
}
|
|
else if (j == 1) {
|
|
correctAnswers[i] = 2;
|
|
}
|
|
else if (j == 2) {
|
|
correctAnswers[i] = 3;
|
|
}
|
|
else {
|
|
correctAnswers[i] = 4;
|
|
}
|
|
}
|
|
|
|
int score = 0;
|
|
int totalAnsweredQuestions = 0;
|
|
int totalCorrectAnswers = 0;
|
|
time_t startTime = time(NULL);
|
|
time_t currentTime;
|
|
int elapsedTime = 0;
|
|
int totalQuestions = sizeof(questions) / sizeof(questions[0]);
|
|
int askedQuestions[40];
|
|
|
|
memset(askedQuestions, 0, sizeof(askedQuestions));
|
|
srand((unsigned int)time(NULL));
|
|
|
|
while (elapsedTime < 60 && totalAnsweredQuestions < totalQuestions) {
|
|
int questionIndex = getRandomQuestionIndex(askedQuestions, totalQuestions);
|
|
askedQuestions[questionIndex] = 1;
|
|
|
|
int correctIndex = correctAnswers[questionIndex] - 1;
|
|
|
|
displayQuestion(questions[questionIndex], answers[questionIndex], correctIndex);
|
|
|
|
int userAnswer;
|
|
printf("Answer (1-4): ");
|
|
scanf_s("%d", &userAnswer);
|
|
}
|
|
}
|
|
|
|
int getRandomQuestionIndex(int askedQuestions[], int totalQuestions) {
|
|
int questionIndex;
|
|
do {
|
|
questionIndex = rand() % totalQuestions;
|
|
} while (askedQuestions[questionIndex] == 1);
|
|
return questionIndex;
|
|
}
|
|
|
|
void displayQuestion(char* question, char* answers[], int correctIndex) {
|
|
printf("\nQuestion: %s\n", question);
|
|
for (int i = 0; i < 4; i++) {
|
|
printf("%d. %s\n", i + 1, answers[i]);
|
|
}
|
|
}
|
|
|
|
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers, char* answers[]) {
|
|
}
|