#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
using namespace std;
int life = 3;
int removeChoices = 3;
string answer = "";
void ShowFiveQuestion(string questions[][6]);
void ShowQuestionWithTwoChoices(string questions[][6], int a, int b);
void ShowIdentification(string questions[][2]);
int main()
{
string easyQuestions[15][6] =
{
{"Question 1", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 2", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 3", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 4", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 5", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
{"Question 7", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 10", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 11", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 12", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 14", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
};
string mediumQuestions[15][6] =
{
{"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 4", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
{"Question 5", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 6", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 7", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 10", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
{"Question 11", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 12", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 13", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 14", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 15", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"}
};
string hardQuestions[15][6] =
{
{"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 4", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 5", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
{"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
{"Question 7", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 8", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 9", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 10", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 11", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 12", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
{"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
{"Question 14", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
{"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
};
string identification[15][2] =
{
{"Question 1", "Answer"},
{"Question 2", "Answer"},
{"Question 3", "Answer"},
{"Question 4", "Answer"},
{"Question 5", "Answer"},
{"Question 6", "Answer"},
{"Question 7", "Answer"},
{"Question 8", "Answer"},
{"Question 9", "Answer"},
{"Question 10", "Answer"},
{"Question 11", "Answer"},
{"Question 12", "Answer"},
{"Question 13", "Answer"},
{"Question 14", "Answer"},
{"Question 15", "Answer"}
};
if(life > 0)
{
cout<< "Round 1: Easy\n";
ShowFiveQuestion(easyQuestions);
}
if(life > 0)
{
cout<< "Round 2: Medium\n";
ShowFiveQuestion(mediumQuestions);
}
if(life > 0)
{
cout<< "Round 3: Hard\n";
ShowFiveQuestion(hardQuestions);
}
if(life > 0)
{
cout<<"Last round: Identification\n";
ShowIdentification(identification);
}
return 0;
}
void ShowIdentification(string questions[][2])
{
srand (time(NULL));
int randomNumber;
int shownQuestion[5] = {0, 0, 0, 0, 0};
bool shown = false;
int totalQuestion = 0;
string playerAnswer = "";
while(totalQuestion < 5)
{
randomNumber = rand() % 15;
//Check if shown
for(int j = 0; j < 5; j++)
{
if(shownQuestion[j] == randomNumber)
{
shown = true;
break;
}
}
if(!shown && life > 0)
{
cout<< "Life: " << life << endl;
cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
cout<< "Answer: ";
cin >> answer;
if(answer == questions[randomNumber][1])
{
cout<< "Correct!\n\n";
cin.get();
cin.get();
system("clear");
}
else
{
cout<< "Incorrect, life is deducted...\n\n";
life--;
cin.get();
cin.get();
system("clear");
}
shownQuestion[totalQuestion] = randomNumber;
totalQuestion++;
}
else if (life == 0)
{
cout<< "Game Over!\n";
break;
}
shown = false;
}
if(life > 0)
{
cout<< "Congratulations! You WIN!!!";
cin.get();
}
system("clear");
}
void ShowFiveQuestion(string questions[][6])
{
srand (time(NULL));
int randomNumber;
int shownQuestion[5] = {0, 0, 0, 0, 0};
bool shown = false;
int totalQuestion = 0;
int choices = 0;
while(totalQuestion < 5)
{
randomNumber = rand() % 15;
//Check if shown
for(int j = 0; j < 5; j++)
{
if(shownQuestion[j] == randomNumber)
{
shown = true;
break;
}
}
if(!shown && life > 0)
{
while(true)
{
cout<< "Life: " << life << " Help: " << removeChoices << endl;
cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
cout<< "Choices: [A] " << questions[randomNumber][1] << endl;
cout<< "Choices: [B] " << questions[randomNumber][2] << endl;
cout<< "Choices: [C] " << questions[randomNumber][3] << endl;
cout<< "Choices: [D] " << questions[randomNumber][4] << endl << endl;
cout<< "Answer (Type 'H', if you want to remove 2 incorrect choices): ";
cin >> answer;
if(answer == "H" && removeChoices > 0)
{
removeChoices--;
system("clear");
ShowQuestionWithTwoChoices(questions, randomNumber, totalQuestion);
break;
}
else if(answer == "H" && removeChoices == 0)
{
cout<< "You can't remove choices anymore... Try again...\n";
cin.get();
cin.get();
system("clear");
}
else if(answer == "A")
{
answer = questions[randomNumber][1];
break;
}
else if(answer == "B")
{
answer = questions[randomNumber][2];
break;
}
else if(answer == "C")
{
answer = questions[randomNumber][3];
break;
}
else if(answer == "D")
{
answer = questions[randomNumber][4];
break;
}
}
if(answer == questions[randomNumber][5])
{
cout<< "Correct!\n\n";
cin.get();
cin.get();
system("clear");
}
else
{
cout<< "Incorrect, life is deducted...\n\n";
life--;
cin.get();
cin.get();
system("clear");
}
shownQuestion[totalQuestion] = randomNumber;
totalQuestion++;
}
else if (life == 0)
{
cout<< "Game Over!";
break;
}
shown = false;
}
if(life > 0)
{
cout<< "Congratulations! You passed this round. Next round!";
cin.get();
}
system("clear");
}
void ShowQuestionWithTwoChoices(string questions[][6], int a, int b)
{
string incorrectChoice = "";
int r = 0;
while(incorrectChoice == "")
{
r = rand() % 5 + 1;
if(questions[a][r] != questions[a][5])
{
incorrectChoice = questions[a][r];
}
}
r = rand() % 2;
cout<< "Life: " << life << endl;
cout<< "Question [" << b + 1 << "/5]: " << questions[a][0] << endl << endl;
if(r == 1)
{
cout<< "Choice [A]: " << incorrectChoice << endl;
cout<< "Choice [B]: " << questions[a][5] << endl;
cout<< "Answer : ";
cin >> answer;
if(answer == "A")
{
answer = incorrectChoice;
}
else if(answer == "B")
{
answer = questions[a][5];
}
}
else if(r == 0)
{
cout<< "Choice [A]: " << questions[a][5] << endl;
cout<< "Choice [B]: " << incorrectChoice << endl;
cout<< "Answer : ";
cin >> answer;
if(answer == "A")
{
answer = questions[a][5];
}
else if(answer == "B")
{
answer = incorrectChoice;
}
}
}