Created
June 29, 2018 20:07
-
-
Save nextrealm/4f2fa435cfd4c5f86d7e2419ea56371e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <cstdlib> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class Question { | |
public: | |
Question(string question, vector<string> loptions, int lanswer); | |
string getQuestion(); | |
vector<string> getAnswers(); | |
int getAnswer(); | |
private: | |
string m_question; | |
vector<string> m_answers; | |
int m_answer; | |
}; | |
Question::Question(string lquestion, vector<string>loptions, int lanswer) { | |
m_question = lquestion; | |
m_answers = loptions; | |
m_answer = lanswer; | |
} | |
string Question::getQuestion() { | |
return m_question; | |
} | |
vector<string> Question::getAnswers() { | |
return m_answers; | |
} | |
int Question::getAnswer() { | |
return m_answer; | |
} | |
int main(int argc, char *argv[]) { | |
vector<Question> questions; | |
questions.push_back(Question("What gender is more vunrable to accidents?", { "Male", "Female" }, 0)); | |
questions.push_back(Question("How much water does the brain consist off?", { "10%", "15%", "55%", "85%", "80%" }, 4)); | |
int score = 0; | |
int current = 0; | |
int guess; | |
cout << "Welcome to the quiz!" << endl; | |
cout << "At the end of the quiz, a results page will be shown..." << endl; | |
while (current < questions.size()) { | |
cout << "Question " << (current + 1) << endl; | |
cout << questions[current].getQuestion() << endl; | |
for (int i = 0; i < questions[current].getAnswers().size(); i++) | |
{ | |
cout << i << ") " << questions[current].getAnswers()[i] << endl; | |
} | |
cin >> guess; | |
if (guess == questions[current].getAnswer()) { | |
cout << "Correct!" << endl; | |
++score; | |
} else { | |
cout << "Incorrect, the correct answer was " << questions[current].getAnswers()[questions[current].getAnswer()] << endl; | |
} | |
current++; | |
} | |
cout << "You scored " << score << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment