Browse Source

refactoring: Gesamtscorefunktion hinzugefügt

remotes/origin/Pascal
Pascal Schneider 11 months ago
parent
commit
85e964a023
  1. 12
      src/timequiz.c
  2. 1
      src/timequiz.h

12
src/timequiz.c

@ -19,6 +19,8 @@ void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalC
int isValidAnswer(int userAnswer); int isValidAnswer(int userAnswer);
void printQuizResult(int totalCorrectAnswers, int totalAnsweredQuestions);
void timequiz() { void timequiz() {
@ -175,9 +177,9 @@ void timequiz() {
} }
//Endnachricht //Endnachricht
printf("\nQuiz finished!\n");
printf("Your total score: %d out of %d\n", totalCorrectAnswers, totalAnsweredQuestions);
printQuizResult(totalCorrectAnswers, totalAnsweredQuestions);
} }
//Zufällige Frage auswählen //Zufällige Frage auswählen
int getRandomQuestionIndex(int askedQuestions[], int totalQuestions) { int getRandomQuestionIndex(int askedQuestions[], int totalQuestions) {
int questionIndex; int questionIndex;
@ -208,3 +210,9 @@ void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalC
int isValidAnswer(int userAnswer) { int isValidAnswer(int userAnswer) {
return (userAnswer >= 1 && userAnswer <= 4); return (userAnswer >= 1 && userAnswer <= 4);
} }
//Ausgabe Endscore
void printQuizResult(int totalCorrectAnswers, int totalAnsweredQuestions) {
printf("\nQuiz finished!\n");
printf("Your total score: %d out of %d\n", totalCorrectAnswers, totalAnsweredQuestions);
}

1
src/timequiz.h

@ -6,5 +6,6 @@ int getRandomQuestionIndex(int askedQuestions[], int totalQuestions);
void displayQuestion(const char* question,const char* answers[], int correctIndex); void displayQuestion(const char* question,const char* answers[], int correctIndex);
void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers,const char* answers[]); void processUserAnswer(int userAnswer, int correctIndex, int* score, int* totalCorrectAnswers,const char* answers[]);
int isValidAnswer(int userAnswer); int isValidAnswer(int userAnswer);
void printQuizResult(int totalCorrectAnswers, int totalAnsweredQuestions);
#endif //ende TIMEQUIZ_H #endif //ende TIMEQUIZ_H
Loading…
Cancel
Save