Browse Source

Added FiftyFifty1 Function for round 4 and 5

main
fdlt3885 2 years ago
parent
commit
52cbc06439
  1. 56
      src/main/quizproject.c
  2. 1
      src/main/quizproject.h

56
src/main/quizproject.c

@ -107,6 +107,38 @@ void fifty_fifty(int question_num) {
};
printf("%s\n",qC[question_num]);
}
void fifty_fifty1(int question_num) {
char options[NUM_QUESTIONS][4][256] = {
{ "A) Berlin", "B) Paris", "C) London", "D) Rome" },
{ "A) George Washington", "B) John Adams", "C) Thomas Jefferson", "D) James Madison" },
{ "A) Los Angeles Lakers", "B) Chicago Bulls", "C) Golden State Warriors", "D) Boston Celtics" },
{ "A) He", "B) H", "C) O", "D) Ne" },
{ "A) Parasite", "B) Joker", "C) Once Upon a Time in Hollywood", "D) 1917" }
};
char correct_answer = answers[question_num];
int num_incorrect = 0;
int incorrect_indices[2];
for (int i = 0; i < 4; i++) {
if (options[question_num][i][0] != correct_answer) {
incorrect_indices[num_incorrect] = i;
num_incorrect++;
}
if (num_incorrect == 2) {
break;
}
}
for (int i = 0; i < 2; i++) {
options[question_num][incorrect_indices[i]][0] = '\0';
}
// display remaining options
for (int i = 0; i < 4; i++) {
if (options[question_num][i][0] != '\0') {
printf("%s\n", options[question_num][i]);
}
}
}
void printOutOption(char qS[][100], char qC[][100],char aS[], int initial, int end, int ranArr[]){
char response;
for (int i = initial; i < end; i++){
@ -253,10 +285,9 @@ void ask_hard_questions(void) {
{ "A) Arthur Conan Doyle", "B) Agatha Christie", "C) Charles Dickens", "D) Stephen King" },
{ "A) To Kill a Mockingbird", "B) Pride and Prejudice", "C) The Great Gatsby", "D) Jane Eyre" }
};
char answers[NUM_QUESTIONS] = { 'B', 'A'}; // correct answers (A, B, C, or D)
char user_answers[NUM_QUESTIONS]; // to store user answers (A, B, C, or D)
char user_answers[NUM_QUESTIONS];
int lifelines[NUM_QUESTIONS] = { 1, 1};
int randNum;
for (int i = 0; i < 2; i++) {
randNum = arr[i];
@ -268,8 +299,16 @@ void ask_hard_questions(void) {
char response;
scanf(" %c", &response);
response = toupper(response);
if (response == 'F' && lifelines[i] == 1) {
fifty_fifty1(randNum);
printf("Enter your answer (A, B, C, or D): ");
scanf(" %c", &user_answers[randNum]);
user_answers[randNum] = toupper(user_answers[randNum]);
lifelines[i] = 0;
}
else {
user_answers[randNum] = response;
// check each answer
}
if (user_answers[randNum] == answers[randNum]) {
score++;
correct(score);
@ -294,7 +333,16 @@ void ask_hard_questions(void) {
char response;
scanf(" %c", &response);
response = toupper(response);
if (response == 'F' && lifelines[i] == 1) {
fifty_fifty1(randNum);
printf("Enter your answer (A, B, C, or D): ");
scanf(" %c", &user_answers[randNum]);
user_answers[randNum] = toupper(user_answers[randNum]);
lifelines[i] = 0;
}
else {
user_answers[randNum] = response;
}
// check each answer
if (user_answers[randNum] == answers[randNum]) {
score++;

1
src/main/quizproject.h

@ -17,6 +17,7 @@ void printOutOption(char [][100], char [][100],char [], int, int, int[] );
void looping(char [][100], char [][100], char [], int []);
void displayThankYouMessage(void);
int* randomNumber();
char answers[NUM_QUESTIONS] = {'B', 'A'};
#define NUM_QUESTIONS 5

Loading…
Cancel
Save