Browse Source

Added random function and two more questions

main
fdlt3885 2 years ago
parent
commit
f65269a77b
  1. 68
      src/main/quizproject.c
  2. 4
      src/main/quizproject.h

68
src/main/quizproject.c

@ -5,6 +5,25 @@
#include <string.h> #include <string.h>
#include "quizproject.h" #include "quizproject.h"
int* randomNumber() {
srand(time(NULL));
int k = 0, p;
static int arr[3];
while(k<3){
int num =rand()%3;
for (p = 0; p < k; p++){
if(arr[p]==num){
break;
}
}
if(p==k){
arr[k++]=num;
}
}
return arr;
}
void displayWelcomeMessage(void) { void displayWelcomeMessage(void) {
printf("\t\t------------------------------------------\n\n"); printf("\t\t------------------------------------------\n\n");
printf("\t\t------------------------------------------\n\n"); printf("\t\t------------------------------------------\n\n");
@ -75,32 +94,35 @@ void wrong(int score1){
void fifty_fifty(int question_num) { void fifty_fifty(int question_num) {
char qC[][100] = { char qC[][100] = {
"A.Mount Everest\nB.Uludag", "A.Mount Everest\nB.Uludag",
"A.USA\nB.China",
"C.Amazon River\nD.The Nile River",
}; };
printf("%s\n",qC[question_num]); printf("%s\n",qC[question_num]);
} }
void printOutOption(char qS[][100], char qC[][100],char aS[]){
void printOutOption(char qS[][100], char qC[][100],char aS[], int initial, int end, int ranArr[]){
char response; char response;
for (int i = 0; i < 1; i++){
printf("%s\n", qS[i]);
printf("%s\n", qC[i]);
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): "); printf("Enter your answer (A, B, C, or D) or use a lifeline (F for 50/50, H for hint): ");
scanf(" %c", &response); scanf(" %c", &response);
response = toupper(response); response = toupper(response);
if (response == 'F') { if (response == 'F') {
fifty_fifty(i);
fifty_fifty(randNum);
printf("Enter your answer (A, B, C, or D): "); printf("Enter your answer (A, B, C, or D): ");
scanf(" %c", &response); scanf(" %c", &response);
response = toupper(response); response = toupper(response);
} }
else if (response == 'H') { else if (response == 'H') {
hint(i);
hint(randNum);
printf("Enter your answer (A, B, C, or D): "); printf("Enter your answer (A, B, C, or D): ");
scanf(" %c", &response); scanf(" %c", &response);
response = toupper(response); response = toupper(response);
} }
if(response == aS[i]){
if(response == aS[randNum]){
score++; score++;
correct(score); correct(score);
} else { } else {
@ -112,14 +134,15 @@ void printOutOption(char qS[][100], char qC[][100],char aS[]){
} }
void looping(char qS[][100], char qC[][100], char aS[]){
void looping(char qS[][100], char qC[][100], char aS[], int randArr[]){
int k = 0; int k = 0;
while(k < 1){ while(k < 1){
printf("\t\t--------------------Round 1-------------------\n\n"); 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"); printf(">>In this round you need to answer 3 questions correctly to move to Round 2<<\n\n");
printOutOption(qS,qC,aS);//2
int initial = 0, end = 1;
printOutOption(qS,qC,aS,initial,end,randArr);
if (score < 1) { if (score < 1) {
printf("You lost! Better luck next time\n"); printf("You lost! Better luck next time\n");
@ -128,7 +151,8 @@ int k = 0;
printf("\t\t--------------------Round 2-------------------\n\n"); 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"); printf(">>In this round you need to answer 2 questions correctly to move to Round 3<<\n\n");
printOutOption(qS,qC,aS);//3
initial = 1, end = 2;
printOutOption(qS,qC,aS,initial,end,randArr);
} }
if (score < 1) { if (score < 1) {
@ -138,7 +162,8 @@ int k = 0;
printf("\t\t--------------------Round 3-------------------\n\n"); 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"); printf(">>In this round you need to answer 2 questions correctly to move to Round 4<<\n\n");
printOutOption(qS,qC,aS);//3
initial = 2, end = 3;
printOutOption(qS,qC,aS,initial,end,randArr);
} }
@ -152,22 +177,29 @@ int k = 0;
void ask_questions(void) { void ask_questions(void) {
char qS[][100] = { char qS[][100] = {
"What is the name of the tallest mountain in the world?\n"
"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",
}; };
char qC[][100] = {//6 char qC[][100] = {//6
"A.Mount Everest\nB.Uludag\nC.K2\nD.Makalu"
"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",
}; };
char aS[100] = { char aS[100] = {
'A'
'A',
'B',
'D',
}; };
looping(qS,qC,aS);
int* arr = randomNumber();
looping(qS, qC, aS, arr);
} }
@ -246,7 +278,9 @@ void ask_hard_questions(void) {
void hint(int question_num) { void hint(int question_num) {
char qC[][100] = { char qC[][100] = {
"The Tallest mountain is 8,849m."
"The Tallest mountain is 8,849m.",
"It's population is 1.412 billion.",
"The longest river measures 6,650km.",
}; };
printf("%s\n",qC[question_num]); printf("%s\n",qC[question_num]);
} }

4
src/main/quizproject.h

@ -13,8 +13,10 @@ void hint(int);
void correct(int); void correct(int);
void wrong(int); void wrong(int);
int score = 0; int score = 0;
void printOutOption(char [][100], char [][100],char []);
void printOutOption(char [][100], char [][100],char [], int, int, int[] );
void looping(char [][100], char [][100], char [], int []);
void displayThankYouMessage(void); void displayThankYouMessage(void);
int* randomNumber();
#define NUM_QUESTIONS 5 #define NUM_QUESTIONS 5

Loading…
Cancel
Save