How to add a second player for trivia game.

I have my code complete, it works and everything, and I find out it has to have two players. Stupid as this sounds..I'm not sure how to do that..I mean I've tried but I just messed things up. Any advice/tips is appreciated.

Header file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef TRIVIA_H
#define TRIVIA_H

#include <string>
using namespace std;

class Trivia
{
	private:
		string question;
		string answer;
		int amount;

	public:
		Trivia();
		Trivia(string question, string answer, int amount);
		~Trivia() {};
		
		void setQuestion(string newQuestion);
		void setAnswer(string newAnswer);
		void setAmount(int newAmount);

		string getQuestion();
		string getAnswer();
		int getAmount();
};
#endif 


Implementation file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Trivia.h"
#include <string>
#include <iostream>
#include <vector>

using namespace std;

Trivia::Trivia()
{
	question = " ";
	answer = " ";
	amount = 0.0;
}

Trivia::Trivia(string question, string answer, int amount)
{
	this -> question = question;
	this -> answer = answer;
	this -> amount = amount;
}

string Trivia::getQuestion()
{
	return question;
}

void Trivia::setQuestion(string newQuestion)
{
	question = newQuestion;
}

string Trivia::getAnswer()
{
	return answer;
}

void Trivia::setAnswer(string newAnswer)
{
	answer = newAnswer;
}

int Trivia::getAmount()
{
	return amount;
}

void Trivia::setAmount(int newAmount)
{
	amount = newAmount;
}


Main file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Trivia.h"
#include <vector>
#include <iostream>
using::cout;
using::cin;

int main(void)
{
	vector <Trivia> triviaList;
	Trivia trivia;

	trivia.setQuestion("\n\nA 64-bit processor can handle how many Bytes? ");
	trivia.setAnswer("8");
	trivia.setAmount(20);
	triviaList.push_back(trivia);

	trivia.setQuestion("\n\nThe maximum amount of RAM a 32-bit OS can handle is? ");
	trivia.setAnswer("4");
	trivia.setAmount(20);
	triviaList.push_back(trivia);

	trivia.setQuestion("\n\nThe only language a processor understands is? ");
	trivia.setAnswer("binary");
	trivia.setAmount(20);
	triviaList.push_back(trivia);

	trivia.setQuestion("\n\nIf you use the new operator in C++, you MUST include the? ");
	trivia.setAnswer("delete");
	trivia.setAmount(20);
	triviaList.push_back(trivia);

	trivia.setQuestion("\n\nSRAM is better than DRAM because SRAM does not need to be? ");
	trivia.setAnswer("refreshed");
	trivia.setAmount(20);
	triviaList.push_back(trivia);

	int winnings = 0;
	
	std::cout << "Welcome to the Trivia Game!\n";

	for (int i = 0; i < triviaList.size(); i++)
	{
		std::cout << "\nYou have $" << winnings;
		std::cout << triviaList[i].getQuestion();

		string answer;
		getline(cin, answer);

		if (answer == triviaList[i].getAnswer())
		{
			std::cout << "That is correct! You win $"
					  << triviaList[i].getAmount();
					     winnings += triviaList[i].getAmount();
		}
		else
		{
			std::cout << "Sorry, the correct answer is: " <<
				 triviaList[i].getAnswer();
		}
	}

	std::cout << "\nGame Over. Your total winnings are: $" << winnings <<"\n\n";
}
Topic archived. No new replies allowed.