Alright, so the srand goes out of the loop, got that.
As far as the system/goto commands, I know they're bad. But, for now since I'm only a beginner and this isn't an official project or anything, just something I'm messing around with for me, I'll keep it. But eventually, I'll rework the code to not include those commands. Thanks!
Ah, I get it! So total score is the exact same as questionAmount. But I forgot why I needed to create another variable for questionAmount. I remember I was seriously doing some hard thinking about that, and there was a reason why I needed two variables for the same amount (or maybe there isn't a reason).
So I'll just make totalscore equal the questionAmount by doing:
1 2 3 4 5 6 7 8 9 10 11 12
|
// Question Amount
int question(1), questionAmount;
cout << "\nType in the of questions you'd like\n";
cout << "(or type 0 to go back to the menu):\n";
cin >> questionAmount;
if (questionAmount == 0) {
system("cls");
goto themenu;
}
int score(0), totalscore(questionAmount);
| |
I also noticed my question number wasn't going up, was stuck at question 1, so I added this:
1 2 3 4 5 6 7 8 9 10 11
|
if (nan == a + b)
{
cout << "\n\tCorrect!\n"; // Correct
score += 1; // + 1 score
question += 1; // + 1 question amount
cout << "Your current score: " << score << " / " << totalscore << "\n\n";
} else {
cout << "\n\tWrong!\n"; // Wrong
question += 1; // + 1 question amount
cout << "Your current score: " << score << " / " << totalscore << "\n\n";
}
| |
And I just noticed it would stop at question 2/3, rather than 3/3, so I added:
while (question < questionAmount + 1) {
And it seems to be working just fine now.
Thanks for the help, guys!