I have a homework assignment to create a trivia game with classes
below is my header file, accessor/mutator file, and main file
When i run the program, it doesn't loop through the program but post the results and closes. I'm guessing it's something easy but i just need a second set of eyes
/*
create a simple trivia game for two players. the program should start with player one each player gets a turn at answering 5 trivia questions (10 total)
when a question is displayed, four possible answer are displayed, only one answer is the correct answer. correct answer earns a point
after answers have been selected for all questions the program will display the number of points earned by each player and declare the winner
*/
#include "stdafx.h"
#include "question.h"
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
void questionAns(question[], int);
int main() {//start main
question trivia[10]; //10 instances of Game class
int count = 0; //used to count through loop and as index
//variables to hold players answers
int onechoice;
int twochoice;
//holds total points for each player
int onePoints = 0;
int twoPoints = 0;
int x;
cout << "Let's test your math knowledge." << endl;
cout << "May the best person win" << endl;
//creating questions and answer in each object
// QUESTION ONE
trivia[0].setQues("What is the sum of two plus two?");
trivia[0].setAnswer1("1. six");
trivia[0].setAnswer2("2. three");
trivia[0].setAnswer3("3. eight");
trivia[0].setAnswer4("4. four");
trivia[0].setCorrect(4);
// QUESTION TWO
trivia[1].setQues("What is the product of thirty divided by five?");
trivia[1].setAnswer1("1. two");
trivia[1].setAnswer2("2. six");
trivia[1].setAnswer3("3. ten");
trivia[1].setAnswer4("4. seven");
trivia[1].setCorrect(2);
// QUESTION THREE
trivia[2].setQues("What is the product of eighteen divided by nine minus one?");
trivia[2].setAnswer1("1. one");
trivia[2].setAnswer2("2. seven");
trivia[2].setAnswer3("3. six");
trivia[2].setAnswer4("4. three");
trivia[2].setCorrect(1);
// QUESTION FOUR
trivia[3].setQues("If you drive eighty miles and consume four gallons of gas, how many miles per gallon did you achieve?");
trivia[3].setAnswer1("1. thirteen");
trivia[3].setAnswer2("2. forty");
trivia[3].setAnswer3("3. twenty");
trivia[3].setAnswer4("4. eighty");
trivia[3].setCorrect(3);
// QUESTION FIVE
trivia[4].setQues("If you drive a constant sixty miles per hour how many miles will you cover in three hours?");
trivia[4].setAnswer1("1. eighteen");
trivia[4].setAnswer2("2. one hundred and twenty");
trivia[4].setAnswer3("3. one hundred and eighty");
trivia[4].setAnswer4("4. none of the above");
trivia[4].setCorrect(3);
// QUESTION SIX
trivia[5].setQues("You have to be to work at seven thirty every morning, It normally takes you twenty minutes to drive to work. What time should you leave?");
trivia[5].setAnswer1("1. Seven ten");
trivia[5].setAnswer2("2. six o'clock");
trivia[5].setAnswer3("3. six thirty");
trivia[5].setAnswer4("4. none of the above");
trivia[5].setCorrect(1);
// QUESTION SEVEN
trivia[6].setQues("There is a road construction causing a ten minute detour. What time should you leave?");
trivia[6].setAnswer1("1. six thirty");
trivia[6].setAnswer2("2. seven o'clock");
trivia[6].setAnswer3("3. eight o'clock");
trivia[6].setAnswer4("4. seven o'clock");
trivia[6].setCorrect(2);
// QUESTION EIGHT
trivia[7].setQues("If your vehicle has a 20 gallon gas tank and gas costs 3.79 per gallon. how much would it cost to fill 5 gallons");
trivia[7].setAnswer1("1. seventy five dollars and eighty cents");
trivia[7].setAnswer2("2. it's free");
trivia[7].setAnswer3("3. eighteen dollars and ninty-five cents");
trivia[7].setAnswer4("4. three dollars and seventy-nine cents");
trivia[7].setCorrect(3);
// QUESTION NINE
trivia[8].setQues("What is pi");
trivia[8].setAnswer1("1. 3.14159");
trivia[8].setAnswer2("2. food");
trivia[8].setAnswer3("3. 3.15149");
trivia[8].setAnswer4("4. 2");
trivia[8].setCorrect(1);
// QUESTION TEN
trivia[9].setQues("What is the reduced mixed number for one point eight zero");
trivia[9].setAnswer1("1. three fourths");
trivia[9].setAnswer2("2. two and one thirds");
trivia[9].setAnswer3("3. one and three fourths");
trivia[9].setAnswer4("4. four thirds");
trivia[9].setCorrect(3);
while(count < 9, count++) {//start while loop for actual game
cout << setw(10) << " QUESTION " << (count + 1) << endl;
questionAns(trivia,count);
cout << "Player 1's answer: ";
cin >> onechoice;
cout << "Player 2's answer: ";
cin >> twochoice;
//if statements check to see if answers are right, if they are right then they get a point
if(trivia[count].getCorrect() == onechoice) {
onePoints++;
}
if(trivia[count].getCorrect() == twochoice) {
twoPoints++;
}
cout << endl << endl;
}
if ( onePoints == twoPoints) {
cout << "Both players were tied." << endl;
}
if ( onePoints > twoPoints) {
cout << "Player one wins!" << endl;
}else {
cout << "Plaer two wins!" << endl;
}
cout << "Thanks for playing, press any key to exit.";
cin >> x;
}
void questionAns(question z[], int count)
{
cout << z[count].getQues() << endl;
cout << z[count].getAnswer1() << endl;
cout << z[count].getAnswer2() << endl;
cout << z[count].getAnswer3() << endl;
cout << z[count].getAnswer4() << endl;
}