#include "question.h"
#include <string>
#include <iomanip>
#include <iostream>
usingnamespace std;
void questionAnswers(question [], int);
int main()
{
char response, start;
do
{
question Game[10];
int count = 0;
int player1Choice, player2Choice; // Holds the player's answers.
int player1Points = 0, player2Points = 0; // Holds the player's total points.
// Describe the game to the user.
cout << "Welcome to:" << endl << endl;
cout << "-------------the FANTABULOUS TRIVIA GAME!-------------" << endl << endl;
cout << "This is the TWO PLAYER GAME where you will be challenged by TRIVIA QUESTIONS!" << endl;
cout << "You will be asked a total of 10 questions." << endl;
cout << "First one to get them all right with the most points WINS!" << endl << endl;
// Ask the user if they would like to start the game.
cout << "Ready to start?" << endl;
cout << "Please type 'Y' or 'y' for YES." << endl;
cout << "Alternatively type 'N' or 'n' for NO." << endl;
cin >> start;
// If loop to start the game.
if(start == 'Y' || start == 'y')
{
// First question.
Game[0].setQuestions("What is the capital of New Jersey?");
Game[0].setAnswer1("1. Alaska");
Game[0].setAnswer2("2. Toronto");
Game[0].setAnswer3("3. applesauce");
Game[0].setAnswer4("4. Trenton");
Game[0].setCorrectAnswer(4);
// Second question.
Game[1].setQuestions("What is America's favorite past time?");
Game[1].setAnswer1("1. War");
Game[1].setAnswer2("2. Football");
Game[1].setAnswer3("3. Baseball");
Game[1].setAnswer4("4. Soccer");
Game[1].setCorrectAnswer(3);
// Third question.
Game[2].setQuestions("What makes the grass green?");
Game[2].setAnswer1("1. Green");
Game[2].setAnswer2("2. Chlorophyll");
Game[2].setAnswer3("3. Germs");
Game[2].setAnswer4("4. Yellow");
Game[2].setCorrectAnswer(2);
// Fourth question.
Game[3].setQuestions("What year did Germany invade Poland at the start of WW2?");
Game[3].setAnswer1("1. 1939");
Game[3].setAnswer2("2. 1856");
Game[3].setAnswer3("3. 1400");
Game[3].setAnswer4("4. 1946");
Game[3].setCorrectAnswer(1);
// Fifth question.
Game[4].setQuestions("What is the eight planet of the solar system?");
Game[4].setAnswer1("1. Mars");
Game[4].setAnswer2("2. Jupiter");
Game[4].setAnswer3("3. Poseidon");
Game[4].setAnswer4("4. Neptune");
Game[4].setCorrectAnswer(4);
// Sixth question.
Game[5].setQuestions("Which famous superhero was from the planet Krypton?");
Game[5].setAnswer1("1. Batman");
Game[5].setAnswer2("2. Deadpool");
Game[5].setAnswer3("3. Superman");
Game[5].setAnswer4("4. Wolverine");
Game[5].setCorrectAnswer(3);
// Seventh question.
Game[6].setQuestions("What 2010 film had to do with entering people's dreams?");
Game[6].setAnswer1("1. Shutter Island");
Game[6].setAnswer2("2. Hugo");
Game[6].setAnswer3("3. The Matrix");
Game[6].setAnswer4("4. Inception");
Game[6].setCorrectAnswer(4);
// Eighth question.
Game[7].setQuestions("What is 44 divided by 4");
Game[7].setAnswer1("1. 11");
Game[7].setAnswer2("2. 89");
Game[7].setAnswer3("3. 6");
Game[7].setAnswer4("4. 7");
Game[7].setCorrectAnswer(1);
// Ninth question.
Game[8].setQuestions("When is Independence Day?");
Game[8].setAnswer1("1. February 27");
Game[8].setAnswer2("2. July 4");
Game[8].setAnswer3("3. May 5");
Game[8].setAnswer4("4. July 2");
Game[8].setCorrectAnswer(2);\
// Tenth question.
Game[9].setQuestions("What is the Law of Conservation of Energy?");
Game[9].setAnswer1("1. That energy can be created, but not destroyed.");
Game[9].setAnswer2("2. That energy is simply an illsuion.");
Game[9].setAnswer3("3. That energy cannot be created nor destroyed.");
Game[9].setAnswer4("4. That energy cannot be created, but can be destroyed.");
Game[9].setCorrectAnswer(2);
// While loop for the actual game.
while(count < 9)
{
cout << setw(10) << "Question #" << (count + 1) << "." << endl;
questionAnswers(Game, count);
cout << "Player 1 Answer: ";
cin >> player1Choice;
cout << "Player 2 Answer: ";
cin >> player2Choice;
// If Player 1 is right, they get a point.
if(Game[count].getCorrectAnswer() == player1Choice)
{
player1Points++;
}
// If Player 2 is right, they get a point.
if(Game[count].getCorrectAnswer() == player2Choice)
{
player2Points++;
}
count++;
}
// If loops to determine who wins.
if (player1Points > player2Points)
{
cout << "Player 1 WINS!" << endl;
cout << "Congratulations Player 1!!" << endl;
}
if (player1Points < player2Points)
{
cout << "Player 2 WINS!" << endl;
cout << "Congratulations Player 2!!" << endl;
}
if (player1Points == player2Points)
{
cout << "Player 1 and Player 2 are now tied!" << endl;
cout << "You both LOST!!" << endl;
}
}
elseif(start == 'n' || start == 'N')
{
cout << "Thanks for your participation in the FANTABULUS TRIVIA GAME!" << endl;
}
// Ask the user if they would like to rerun the program.
cout << endl << "\nWould you like to run the program again?" << endl;
cin >> response;
cout << endl;
} while (response == 'y' || response == 'Y');
return 0;
}
void questionAnswers(question i[], int count)
{
cout << i[count].getQuestions() << endl;
cout << i[count].getAnswer1() << endl;
cout << i[count].getAnswer2() << endl;
cout << i[count].getAnswer3() << endl;
cout << i[count].getAnswer4() << endl << endl;
}
@ Bourgond Aries
normally i would have done that, but the problem needed an array.
Although, I probably could have done so anyways and just put the array into the main, instead of trying to call it from the class.
But then again, I'm not too sure how well that would have worked out.
In any case, thanks for all the suggestions everyone!