code
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 playGame() {
srand(time(NULL));
int contestantIndex = rand() % contestantCount;
Contestant *currentContestant = &contestants[contestantIndex];
currentContestant->correctAnswers = 0;
if (lifelinesUsed < 2) {
printf("Use lifeline? (1 for 50/50, 2 for Double Dip, 0 to skip): ");
int lifeline;
scanf("%d", &lifeline);
if (lifeline == 1 || lifeline == 2) {
useLifeline(questionIndex);
lifelinesUsed++;
}
}
int answer;
printf("Your answer: ");
scanf("%d", &answer);
if (answer == questions[questionIndex].correctAnswer) {
printf("Correct!\n");
currentContestant->correctAnswers++;
} else {
printf("Wrong! The correct answer was %d\n",
questions[questionIndex].correctAnswer);
break;
}
}
printf("Game Over. %s answered %d questions correctly.\n", currentContestant-
>name, currentContestant->correctAnswers);
}
void showStatistics() {
printf("\nStatistics Function Placeholder\n");
}
void showMenu() {
printf("\nWho Wants to Be a Millionaire\n");
printf("1. Play Game\n");
printf("2. Load Questions\n");
printf("3. Load Contestants\n");
printf("4. Show Statistics\n");
printf("5. Exit\n");
}