statistics code
statistics code
h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Question questions[MAX_QUESTIONS];
Contestant contestants[MAX_CONTESTANTS];
int questionCount = 0, contestantCount = 0;
int main() {
int choice;
do {
showMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
playGame();
break;
case 2:
loadQuestions("questions.txt");
break;
case 3:
loadContestants("contestants.txt");
break;
case 4:
showStatistics();
break;
case 5:
printf("Exiting the game.\n");
break;
default:
printf("Invalid choice, please try again.\n");
}
} while (choice != 5);
return 0;
}
void showStatistics() {
FILE *file = fopen("statistics.txt", "r");
if (!file) {
printf("No statistics available.\n");
return;
}
int found = 0;
for (int i = 0; i < cityIndex; i++) {
if (strcmp(cityList[i], city) == 0) {
cityCount[i]++;
found = 1;
break;
}
}
if (!found) {
strcpy(cityList[cityIndex], city);
cityCount[cityIndex++] = 1;
}
for (int i = 0; i < MAX_CATEGORIES; i++) {
if (strcmp(questions[i].category, category) == 0) {
categoryCorrect[i] += correctAnswers;
categoryTotal[i]++;
break;
}
}
}
fclose(file);