Browse Source

refactoring: Kommentare für Spiel hinzugefügt

remotes/origin/Pascal
Pascal Schneider 11 months ago
parent
commit
a9cc69fbb2
  1. 8
      src/timequiz.c

8
src/timequiz.c

@ -8,6 +8,7 @@
#define ASKED_QUESTIONS 40
//Funktionen des Codes
void timequiz();
int getRandomQuestionIndex(int askedQuestions[], int totalQuestions);
@ -18,8 +19,11 @@ void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalC
int isValidAnswer(int userAnswer);
void timequiz() {
//Willkommensnachricht
printf("Welcome to our Time Quiz!\n");
printf("You have 60 seconds to answer the questions. Have fun!\n");
@ -132,7 +136,7 @@ void timequiz() {
correctAnswers[i] = 4;
}
}
//Variablen für das Spiel
int score = 0;
int totalAnsweredQuestions = 0;
int totalCorrectAnswers = 0;
@ -145,6 +149,7 @@ void timequiz() {
memset(askedQuestions, 0, sizeof(askedQuestions));
srand((unsigned int)time(NULL));
//While-Schleife für Spielausführung
while (elapsedTime < 60 && totalAnsweredQuestions < totalQuestions) {
int questionIndex = getRandomQuestionIndex(askedQuestions, totalQuestions);
askedQuestions[questionIndex] = 1;
@ -169,6 +174,7 @@ void timequiz() {
elapsedTime = (int)difftime(currentTime, startTime);
}
//Endnachricht
printf("\nQuiz finished!\n");
printf("Your total score: %d out of %d\n", totalCorrectAnswers, totalAnsweredQuestions);
}

Loading…
Cancel
Save