#include <stdio.
h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_QUESTIONS 100
#define MAX_CONTESTANTS 50
#define MAX_CATEGORIES 10
#define TIMER_LIMIT 20
const int PRIZES[5] = {20000, 100000, 250000, 500000, 1000000};
// Structure to store questions
typedef struct {
char category[50];
char text[256];
char choices[4][100];
int correctAnswer;
int difficulty;
} Question;
// Structure to store contestant information
typedef struct {
char name[50];
int birthYear;
char phone[15];
char city[50];
int correctAnswers;
} Contestant;
Question questions[MAX_QUESTIONS];
Contestant contestants[MAX_CONTESTANTS];
int questionCount = 0, contestantCount = 0;
void loadQuestions(const char *filename);
void loadContestants(const char *filename);
void playGame();
void showMenu();
void showStatistics();
void useLifeline(int questionIndex, int *eliminatedOptions, int type);
void saveStatistics(Contestant *);
int main() {
int choice;
do {
showMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
playGame();
break;
case 2:
loadQuestions("[Link]");
break;
case 3:
loadContestants("[Link]");
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("[Link]", "r");
if (!file) {
printf("No statistics available.\n");
return;
}
char name[50], city[50], category[50];
int correctAnswers, birthYear;
int mostCorrect = 0, leastCorrect = 9999;
char bestContestant[50] = "", worstCategory[50] = "", bestCategory[50] = "";
int categoryCorrect[MAX_CATEGORIES] = {0}, categoryTotal[MAX_CATEGORIES] = {0};
int ageGroupCorrect[3] = {0}, ageGroupCount[3] = {0};
char mostPopularCity[50] = "";
int cityCount[MAX_CONTESTANTS] = {0}, maxCityCount = 0;
char cityList[MAX_CONTESTANTS][50];
int cityIndex = 0;
while (fscanf(file, "%49[^,], %d correct answers, %d, %49[^,], %49[^\n]\n",
name, &correctAnswers, &birthYear, city, category) == 5) {
if (correctAnswers > mostCorrect) {
mostCorrect = correctAnswers;
strcpy(bestContestant, name);
}
if (correctAnswers < leastCorrect) {
leastCorrect = correctAnswers;
strcpy(worstCategory, category);
}
int ageGroup = (birthYear > 1993) ? 0 : (birthYear > 1973 ? 1 : 2);
ageGroupCorrect[ageGroup] += correctAnswers;
ageGroupCount[ageGroup]++;
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);
for (int i = 0; i < cityIndex; i++) {
if (cityCount[i] > maxCityCount) {
maxCityCount = cityCount[i];
strcpy(mostPopularCity, cityList[i]);
}
}
for (int i = 0; i < MAX_CATEGORIES; i++) {
if (categoryTotal[i] > 0) {
if (categoryCorrect[i] > categoryCorrect[0]) {
strcpy(bestCategory, questions[i].category);
}
if (categoryCorrect[i] < categoryCorrect[0]) {
strcpy(worstCategory, questions[i].category);
}
}
}
printf("Most Successful Contestant: %s with %d correct answers\n",
bestContestant, mostCorrect);
printf("Most Correctly Answered Category: %s\n", bestCategory);
printf("Least Correctly Answered Category: %s\n", worstCategory);
printf("Average correct answers per age group:\n");
printf(" Age <= 30: %.2f\n", ageGroupCount[0] ? (float)ageGroupCorrect[0] /
ageGroupCount[0] : 0);
printf(" Age 31-50: %.2f\n", ageGroupCount[1] ? (float)ageGroupCorrect[1] /
ageGroupCount[1] : 0);
printf(" Age > 50: %.2f\n", ageGroupCount[2] ? (float)ageGroupCorrect[2] /
ageGroupCount[2] : 0);
printf("City with most participants: %s (%d participants)\n", mostPopularCity,
maxCityCount);
}