Last active
August 7, 2021 02:29
-
-
Save RascalTwo/f5e210b3afae421de71ef912a854dd98 to your computer and use it in GitHub Desktop.
C++ Multiple choices
This file contains 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 <fstream> | |
#include <iostream> | |
using namespace std; | |
typedef struct Question { | |
string text; | |
string one; | |
string two; | |
string three; | |
string four; | |
string correct; | |
} Question; | |
void getQuestion(Question &question, const string filename, | |
const unsigned int qn) { | |
fstream infile(filename.c_str(), ios::in); | |
if (!infile) | |
return; | |
string dump; | |
for (int i = 0; i < (qn * 6); i++) | |
getline(infile, dump); | |
getline(infile, question.text); | |
getline(infile, question.one); | |
getline(infile, question.two); | |
getline(infile, question.three); | |
getline(infile, question.four); | |
getline(infile, question.correct); | |
} | |
int main() { | |
const unsigned int QUESTION_COUNT = 20; | |
const string INPUT_FILENAME = "questions.txt"; | |
srand(time(NULL)); | |
unsigned int score = 0; | |
unsigned int questionArray[QUESTION_COUNT] = {0}; | |
Question question; | |
for (int _ = 0; _ < QUESTION_COUNT; _++) { | |
int qn = 0; | |
while (true) { | |
qn = rand() % QUESTION_COUNT; | |
if (!questionArray[qn]) | |
break; | |
} | |
questionArray[qn] = qn; | |
getQuestion(question, INPUT_FILENAME, questionArray[qn]); | |
cout << question.text << endl | |
<< "1) " << question.one << endl | |
<< "2) " << question.two << endl | |
<< "3) " << question.three << endl | |
<< "4) " << question.four << endl; | |
char response; | |
cin >> response; | |
if (response == question.correct[0]) | |
score++; | |
} | |
cout << "You got " << int((score / (double)QUESTION_COUNT) * 100) | |
<< "\% correct, " << score << "/" << QUESTION_COUNT << endl; | |
return 0; | |
} |
This file contains 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
What is the capital of USA | |
Atlanta | |
Washington DC | |
New York | |
Chicago | |
2 | |
What is the capital of United Kingdom | |
London | |
Scotland | |
Birmingham | |
Heathrow | |
1 | |
What is the capital of New York | |
Syracuse | |
Albany | |
Buffalo | |
New York City | |
1 | |
What is the capital of California | |
San Diego | |
San Francisco | |
Los Angeles | |
Sacramento | |
4 | |
What is the capital of Canada | |
Toronto | |
Ottawa | |
Nova Scotia | |
Victoria | |
2 | |
Where is Los Angeles | |
California | |
San Diego | |
Nevada | |
Utah | |
1 | |
Where is Louisiana | |
Canada | |
France | |
USA | |
Mexico | |
3 | |
What is capital of France | |
Berlin | |
Paris | |
Belgium | |
London | |
2 | |
Which state is in the west coast | |
Utah | |
California | |
Illinois | |
New York | |
2 | |
Which state is in East Coast | |
California | |
San Diego | |
New York | |
Nevada | |
3 | |
Which state is biggest | |
California | |
Florida | |
Nevada | |
Utah | |
1 | |
which state is smallest | |
California | |
Texas | |
Florida | |
Vermont | |
4 | |
Which state in in EST | |
California | |
San Diego | |
Florida | |
Nevada | |
3 | |
Which state is in PST | |
New York Diego | |
California | |
Illinois | |
Florida | |
2 | |
Which Country is on the North of US | |
Canada | |
Mexico | |
Brazil | |
France | |
1 | |
Which Country is in Asia | |
Canada | |
China | |
Brazil | |
France | |
2 | |
Which Country is in Europe | |
Canada | |
China | |
Brazil | |
France | |
4 | |
Which Country is in South America | |
Canada | |
China | |
Brazil | |
France | |
3 | |
Which state is east of Mississippi River | |
Virginia | |
Colorado | |
Nevada | |
South Dakota | |
1 | |
Which state is west of Mississippi River | |
Virginia | |
Florida | |
Nevada | |
Alabama | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment