You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
458 lines
17 KiB
458 lines
17 KiB
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include "quizproject.h"
|
|
char answers[NUM_QUESTIONS] = {'B', 'A', 'A','B','A'};
|
|
|
|
int* randomNumber() {
|
|
srand(time(NULL));
|
|
int k = 0, p;
|
|
static int arr[13];
|
|
while(k<13){
|
|
int num =rand()%13;
|
|
for (p = 0; p < k; p++){
|
|
if(arr[p]==num){
|
|
break;
|
|
}
|
|
}
|
|
if(p==k){
|
|
arr[k++]=num;
|
|
}
|
|
}
|
|
return arr;
|
|
}
|
|
|
|
void displayWelcomeMessage(void) {
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t Welcome to The Quiz \n\n");
|
|
printf("\t\t------------------------------------------\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t Press 'Enter' to join the Game \n");
|
|
char joinGame;
|
|
scanf("%c", &joinGame);
|
|
joinGame = toupper(joinGame);
|
|
if (joinGame != ' ') {
|
|
char vorName[100] ={0};
|
|
char nachName[100] ={0};
|
|
printf("\t\t Please enter your First Name \n");
|
|
scanf("%s", vorName);
|
|
printf("\t\t Please enter your Surname \n");
|
|
scanf("%s", nachName);
|
|
displayGameInstructions(vorName, nachName);
|
|
}
|
|
|
|
}
|
|
|
|
void displayGoodLuckMessage(void) {
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t GOOD LUCK! \n\n");
|
|
printf("\t\t------------------------------------------\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
}
|
|
|
|
void displayGameInstructions(char vorName[], char nachName[]) {
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t Hello %s %s! \n\n", vorName, nachName);
|
|
printf("\t\t To start this game, here are the Instructions\n\n");
|
|
printf("\t\t------------------------------------------\n");
|
|
printf("\t\t------------------------------------------\n\n");
|
|
printf("\t\t>>You will be presented with questions from\n");
|
|
printf("\t\tRound 1 to Round 3(Easy rounds) and Round\n");
|
|
printf("\t\t4 to Round 5(Hard rounds).<<\n");
|
|
printf("\t\t>>For every question you have four options (A, B, C, D).<<\n");
|
|
printf("\t\t>>For each question, you can either choose the\n");
|
|
printf("\t\tanswer from the four options or use a lifeline.<<\n\n");
|
|
printf("\t\t>>To Pass Through Round 1: You have to get 3 out of 5 correct.<<\n");
|
|
printf("\t\t>>To Pass Through Round 2: You have to get 3 out of 5 correct.<<\n");
|
|
printf("\t\t>>To Pass Through Round 3: You have to get 4 out of 5 correct.<<\n");
|
|
printf("\t\t>>To Pass Through Round 4: You have to get 4 out of 5 correct.<<\n");
|
|
printf("\t\t>>To Pass Through Round 5: You have to get 5 out of 5 correct.<<\n\n");
|
|
printf("\t\t>>If you choose the wrong answer, you lose a point.<<\n\n");
|
|
printf("\t\tYou may lose the game if not you don't have enough points to pass to the next round.\n\n");
|
|
printf("\t\tIf you use a lifeline and still choose the wrong answer, you lose the game.\n");
|
|
}
|
|
void displayLifelineInstructions(void) {
|
|
printf("\t\t>>You have the following lifelines available:<< \n");
|
|
printf("\t\t>>'F' 50-50: Eliminates two incorrect answers.<< \n");
|
|
printf("\t\t>>'H' Hint: Reveals a hint for the answer.<<\n");
|
|
}
|
|
|
|
void displayInstructions(void) {
|
|
displayWelcomeMessage();
|
|
displayLifelineInstructions();
|
|
displayGoodLuckMessage();
|
|
}
|
|
|
|
void correct(int score2){
|
|
printf("\nCorrect!\n");
|
|
printf("You have %d points now\n\n", score);
|
|
}
|
|
void wrong(int score1){
|
|
printf("\nWrong!\n");
|
|
printf("You have %d points now\n\n", score);
|
|
}
|
|
|
|
void fifty_fifty(int question_num) {
|
|
char qC[][100] = {
|
|
"A.Mount Everest\nB.Uludag",
|
|
"A.USA\nB.China",
|
|
"C.Amazon River\nD.The Nile River",
|
|
"A.San Fransisco\nB.San Diego",
|
|
"C.Merida\nD.Mexico city",
|
|
"C.Russia\nD.USA\n",
|
|
"A.Alaska\nB.Washington",
|
|
"C.Toronto\nD.Ottawa",
|
|
"A.Egypt\nB.Mexico",
|
|
"A.Surat Thani\nB.Bangkok",
|
|
"B.Mexico\nC.USA",
|
|
"C.Venice\nD.Naples",
|
|
"B.Cluny\nC.The Louvre"
|
|
};
|
|
printf("%s\n",qC[question_num]);
|
|
}
|
|
|
|
void hintForHardQuestions(int question_num) {
|
|
char hints[NUM_QUESTIONS][256] = {
|
|
"The city is known for its iconic landmarks and romantic atmosphere.",
|
|
"He was a general in the American Revolutionary War and is considered the Father of His Country.",
|
|
"This team has won the most NBA championships in history, with a total of 16 championships.",
|
|
"It is the lightest and most abundant chemical element in the universe.",
|
|
"This South Korean film became the first non-English language film to win the Academy Award for Best Picture."
|
|
};
|
|
printf("Hint: %s\n", hints[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++){
|
|
int randNum = ranArr[i];
|
|
printf("[%d] %s\n", i+1, qS[randNum]);
|
|
printf("%s\n", qC[randNum]);
|
|
printf("Enter your answer (A, B, C, or D) or use a lifeline (F for 50/50, H for hint): ");
|
|
scanf(" %c", &response);
|
|
response = toupper(response);
|
|
if (response == 'F') {
|
|
fifty_fifty(randNum);
|
|
printf("Enter your answer (A, B, C, or D): ");
|
|
scanf(" %c", &response);
|
|
response = toupper(response);
|
|
}
|
|
else if (response == 'H') {
|
|
hint(randNum);
|
|
printf("Enter your answer (A, B, C, or D): ");
|
|
scanf(" %c", &response);
|
|
response = toupper(response);
|
|
|
|
}
|
|
|
|
if(response == aS[randNum]){
|
|
score++;
|
|
correct(score);
|
|
} else {
|
|
wrong(score);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void looping(char qS[][100], char qC[][100], char aS[], int randArr[]){
|
|
|
|
int k = 0;
|
|
while(k < 1){
|
|
printf("\t\t--------------------Round 1-------------------\n\n");
|
|
printf(">>In this round you need to answer 3 questions correctly to move to Round 2<<\n\n");
|
|
|
|
int initial = 0, end = 2;
|
|
printOutOption(qS,qC,aS,initial,end,randArr);
|
|
|
|
if (score < 1) {
|
|
printf("You lost! Better luck next time\n");
|
|
break;
|
|
} else {
|
|
printf("\t\t--------------------Round 2-------------------\n\n");
|
|
printf(">>In this round you need to answer 2 questions correctly to move to Round 3<<\n\n");
|
|
|
|
initial = 2, end = 4;
|
|
printOutOption(qS,qC,aS,initial,end,randArr);
|
|
}
|
|
|
|
if (score < 1) {
|
|
printf("You lost! Better luck next time\n");
|
|
break;
|
|
} else {
|
|
printf("\t\t--------------------Round 3-------------------\n\n");
|
|
printf(">>In this round you need to answer 2 questions correctly to move to Round 4<<\n\n");
|
|
|
|
initial = 4, end = 7;
|
|
printOutOption(qS,qC,aS,initial,end,randArr);
|
|
|
|
}
|
|
|
|
k++;
|
|
}
|
|
if (score < 2) {
|
|
printf("\nYour final score: %d\n", score);
|
|
}
|
|
|
|
}
|
|
|
|
void ask_questions(void) {
|
|
char questions[][100] = {
|
|
"What is the name of the tallest mountain in the world?\n",
|
|
"Which country has the largest population in the world??\n",
|
|
"What is the name of the longest river in Africa?\n",
|
|
"What American city is the Golden Gate Bridge located in?\n",
|
|
"What is the capital of Mexico?\n",
|
|
"What is the name of the largest country in the world?\n",
|
|
"What U.S. state is home to no documented poisonous snakes?\n",
|
|
"What is the capital of Canada?\n",
|
|
"What country are the Great Pyramids of Giza located in?\n",
|
|
"What is the capital of Thailand?\n",
|
|
"In which country was Frida Kahlo born?\n",
|
|
"What present-day Italian city does Mt. Vesuvius overlook?\n",
|
|
"The Mona Lisa by Leonardo da Vinci is on display in which Paris museum?\n"
|
|
|
|
|
|
};
|
|
char possible_options[][100] = {
|
|
"A.Mount Everest\nB.Uludag\nC.K2\nD.Makalu",
|
|
"A.USA\nB.China\nC.Russia\nD.India",
|
|
"A.Missisipi River\nB.Yangtze River\nC.Amazon River\nD.The Nile River",
|
|
"A.San Fransisco\nB.San Diego\nC.New York\nD.Los Angeles",
|
|
"A.Oaxaca\nB.Puebla\nC.Merida\nD.Mexico city",
|
|
"A.India\nB.China\nC.Russia\nD.USA",
|
|
"A.Alaska\nB.Washington\nC.Ohio\nD.California",
|
|
"A.Vancouver\nB.Montreal\nC.Toronto\nD.Ottawa",
|
|
"A.Egypt\nB.Mexico\nC.Iceland\nD.Greenland",
|
|
"A.Surat Thani\nB.Bangkok\nC.Phuket\nD.Pattaya City",
|
|
"A.Austria\nB.Mexico\nC.USA\nD.India",
|
|
"A.Milan\nB.Rome\nC.Venice\nD.Naples",
|
|
"A.Carnavalet\nB.Cluny\nC.The Louvre\nD.Musee d'Orsay"
|
|
|
|
|
|
|
|
};
|
|
|
|
char answers[100] = {
|
|
'A',
|
|
'B',
|
|
'D',
|
|
'A',
|
|
'D',
|
|
'C',
|
|
'A',
|
|
'D',
|
|
'A',
|
|
'B',
|
|
'B',
|
|
'D',
|
|
'C'
|
|
|
|
};
|
|
|
|
int* randArr = randomNumber();
|
|
looping(questions, possible_options, answers, randArr);
|
|
|
|
|
|
}
|
|
|
|
void ask_hard_questions(void) {
|
|
|
|
|
|
int k = 0;
|
|
while (k < 1) {
|
|
|
|
int *lessFive = randomNumber();
|
|
int arr[5];
|
|
int p = 0;
|
|
for(int i = 0; i < 11; i++){
|
|
if(lessFive[i] < 5){
|
|
arr[p] = lessFive[i];
|
|
p++;
|
|
}
|
|
}
|
|
|
|
printf("\t\t--------------------Round 4-------------------\n\n");
|
|
printf(">>In this round you need to answer 2 questions correctly to move to Round 5<<\n\n");
|
|
|
|
|
|
char questions[NUM_QUESTIONS][256] = {
|
|
"What is the capital of France?",
|
|
"Who was the first president of the United States?",
|
|
"Which team won the most NBA championships?",
|
|
"What is the chemical symbol for hydrogen?",
|
|
"Which of the following movies won the Academy Award for Best Picture in 2020?"
|
|
};
|
|
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 user_answers[NUM_QUESTIONS];
|
|
int lifelines[NUM_QUESTIONS] = { 1, 1,1,1,1};
|
|
int randNum;
|
|
for (int i = 0; i < 3; i++) {
|
|
randNum = arr[i];
|
|
printf("[%d] %s\n", i + 1, questions[randNum]);
|
|
for (int j = 0; j < 4; j++) {
|
|
printf("%s\n", options[randNum][j]);
|
|
}
|
|
printf("Enter your answer (A, B, C, or D) or use a lifeline (F for 50/50, H for hint): ");
|
|
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 if (response == 'H' && lifelines[i] == 1) {
|
|
hintForHardQuestions(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;
|
|
}
|
|
if (user_answers[randNum] == answers[randNum]) {
|
|
score++;
|
|
correct(score);
|
|
} else {
|
|
wrong(score);
|
|
}
|
|
}
|
|
if ( score < 4) {
|
|
printf("You lost! Better luck next time\n");
|
|
break;
|
|
} else {
|
|
printf("\t\t--------------------Round 5-------------------\n\n");
|
|
printf(">>This is the final round. Good Luck!<<\n\n");
|
|
for (int i = 3; i < 5; i++) {
|
|
|
|
randNum = arr[i];
|
|
printf("[%d] %s\n", i + 1, questions[randNum]);
|
|
for (int j = 0; j < 4; j++) {
|
|
printf("%s\n", options[randNum][j]);
|
|
}
|
|
printf("Enter your answer (A, B, C, or D) or use a lifeline (F for 50/50, H for hint): ");
|
|
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 if (response == 'H' && lifelines[i] == 1) {
|
|
hintForHardQuestions(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);
|
|
} else {
|
|
wrong(score);
|
|
}
|
|
}
|
|
}
|
|
k++;
|
|
}
|
|
printf("\nYour final score: %d\n", score);
|
|
}
|
|
|
|
|
|
void hint(int question_num) {
|
|
char qC[][100] = {
|
|
"Hint:The Tallest mountain is 8,849m.",
|
|
"Hint:It's population is 1.412 billion.",
|
|
"Hint:The longest river measures 6,650km.",
|
|
"Hint:The Golden States Warriors play there.\n",
|
|
"Hint:It is one of the oldest and largest cities in the Americas.\n",
|
|
"Hint:The area of the largest country is 17.1 million km2.\n",
|
|
"Hint:It is the coldest state in the US.",
|
|
"Hint:It is the 4th largest city in Canada.",
|
|
"Hint:It is a dry Country.",
|
|
"Hint:The capital has the longest city name in the world.",
|
|
"Hint:The Native language is Spanish.",
|
|
"Hint:The city that invented Swamp Buggy Racing.",
|
|
"Hint:It is the most visited art museum in the world."
|
|
|
|
};
|
|
printf("%s\n",qC[question_num]);
|
|
}
|
|
|
|
void displayThankYouMessage(void) {
|
|
printf("*******************************\n");
|
|
printf("Thank you for playing QuizGame!\n");
|
|
printf("*******************************\n\n");
|
|
}
|
|
|
|
int main(){
|
|
displayInstructions();
|
|
|
|
printf(">>Press 's' and Enter start the Game<<\n");
|
|
char var, var1 = 's';
|
|
getchar();
|
|
while(var != var1) {
|
|
var = getchar();
|
|
}
|
|
printf("\n");
|
|
ask_questions();
|
|
if (score > 2){
|
|
ask_hard_questions();
|
|
}
|
|
displayThankYouMessage();
|
|
return 0;
|
|
}
|
|
|
|
|