I am trying to fine-tune a Quiz game that asks multiple-choice questions. (EDITED) I was able to figure out a few questions I had, but I am still stuck on the rest.
REQUIREMENTS:
1) 2-Round Game (Warmup Round + Full Game)
2) Multiple Choice Questions
WHAT I'VE COMPLETED SO FAR:
1) Questions are stored in a text file
2) Scores are stored in a text file
3) Full game of 10 questions pulled from text file
4) High Score stored in a text file
ISSUES:
1) No Warmup Round created
4) No reset score created.
QUESTIONS:
1) How can I add a WARMUP Round to my code that will ask the player 3 simple questions and if the user gets 2 of 3 questions correct, they move onto the full game. If they get 2 of the 3 questions wrong, they get placed back at the Main Menu?
2) How can I add a RESET SCORE function that erases the high score from the text file?
I figured out the highscore issue (it was my antivirus not allowing my highscore text file to be updated.)
UPDATED CODE
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include <time.h>
using namespace std;
void help();
void display_score();
int highest_score();
void update_score(string name, int score);
int main() {
char start_option;
string name;
cout << "Enter your name" << endl;
cin >> name;
Home:
system("CLS");
cout << "\t C++ PROGRAM QUIZ GAME" << endl;
cout << " _________________________________________" << endl;
cout << "\t\t WELCOME " << endl;
cout << "\t\t to" << endl;
cout << "\t\t THE GAME" << endl;
cout << " _________________________________________\n";
cout << " _________________________________________\n";
cout << "\t BECOME A MILLIONAIRE!!!!!!!\n";
cout << " _________________________________________\n";
cout << " _________________________________________\n";
cout << "\t > Press S to start the game\n";
cout << "\t > Press V to view the highest score\n";
cout << "\t > Press R to reset score\n";
cout << "\t > Press H for help\n";
cout << "\t > Press Q to quit\n";
cout << " _________________________________________\n";
cin >> start_option;
start_option = toupper(start_option);
if (start_option == 'V') {
display_score();
goto Home;
}
else if (start_option == 'H') {
help();
goto Home;
}
else if (start_option == 'Q') {
return 0;
}
else if (start_option == 'S') {
srand(time(0));
vector<int> check_repeat(30, 0);
string question;
string answer;
string category;
char user_answer;
int sports = 0;
int gk = 0;
int current_affairs = 0;
int counter = 0;
int score = 0;
while (counter < 10) {
int line_counter = 0;
int rand_line = rand() % 24;
if (check_repeat[rand_line] == 0) {
check_repeat[rand_line] = 1;
ifstream file("quiz_bank.txt");
while (rand_line != line_counter) {
getline(file, question);
getline(file, answer);
getline(file, category);
line_counter++;
}
getline(file, question);
getline(file, answer);
getline(file, category);
system("CLS");
cout << "Question Category: " << category << " " << "Question Number: " << counter + 1 << endl;
cout << question << endl;
cin >> user_answer;
user_answer = toupper(user_answer);
if (answer[0] == user_answer) {
system("CLS");
cout << "\t\t\t That is correct!" << endl;
score += 1;
system("pause");
cin.get();
if (category == "SPORTS")
sports++;
else if (category == "GK")
gk++;
else
current_affairs++;
}
else {
system("CLS");
cout << "Question Category: " << category << " " << "Question Number: " << counter + 1 << endl;
cout << question << endl;
cout << "Correct Answer : " << answer << endl;
system("pause");
}
counter++;
}
}
system("CLS");
cout << "\t\tCongratulations . You have completed the quiz!!\n\n";
if (score >= highest_score()) {
cout << "\t\tNEW RECORD!!\n" << endl;
update_score(name, score);
}
cout << "Your Score is: " << score << endl;
cout << "\n\n";
cout << "Category Wise Score -:" << endl;
cout << "\tSports : " << sports * 1 << endl;
cout << "\tGK : " << gk * 1 << endl;
cout << "\tCurrent Affairs : " << current_affairs * 1 << endl;
cout << "To play again press S to Quit press any other Key " << endl;
cin >> start_option;
start_option = toupper(start_option);
if (start_option == 'S') {
goto Home;
}
else
exit(1);
}
else
exit(1);
return 0;
}
void display_score()
{
ifstream file("highest_c++_score.txt");
string name;
int score;
file >> name >> score;
system("CLS");
cout << name << " has the highest Score of " << score << endl;
system("pause");
}
int highest_score()
{
int score;
string name;
ifstream file("highest_c++_score.txt");
file >> name >> score;
return score;
}
void help()
{
cout << "THERE ARE 2 ROUNDS IN THIS GAME.\n";
cout << "[WARM UP ROUND]- You will be asked 3 questions and you must answer 2 of the 3 correctly to advance.\n";
cout << "[MAIN ROUND]- You will be asked ten questions. Each question is worth $ 100,000.\n";
cout << "\t when you reach ONE MILLION, YOU WIN!!\n\n";
system("pause");
}
void update_score(string name, int score)
{
ofstream file("highest_c++_score.txt");
file << name << " " << score;
}
|