Hi everyone, I am doing a jeopardy type game in C++ and it does not run properly wherever I run it. There is also a bad access error on question 5 about "kurtenbach". There are no errors so it runs, but it doesn't run properly. It will randomly select a question but then it will glitch out and repeat right answer or wrong answer a few times until it settles on one. I can't figure out the problem. Sorry if I am unclear. The stuff above it is just the functions, it just says text with a graphic so I don't think the problem is to do with that.
int main ()
{
// declaring variables and arrays
int randomNumber;
int numberQuestion[4];
int rightQuestion;
string questionAnswer[5];
int askedAlready[10];
// while the money earned is less than 800 it keeps looping
while (totalMoney <=800){
// resets random numbers
srand(time(0));
// the welcome screen and first question
showMenu();
// if over 8 questions are correct, it displays the final question
if (rightQuestion >=8){
finalQuestion();
sleep (5);
return 0;
}
cout << "Your number of questions right is: " << rightQuestion << endl;
// random numbers
srandom (time(NULL));
randomNumber = random()% 9+1;
// switch statement
switch (randomNumber){
case 0:
{
// no code here because it is impossible for case 0 to happen, but without it the switch statement is incomplete since it starts at 0
}
case 1:
// if question was asked already then don't ask it again
if (askedAlready[0] <1){
firstQuestion();
cin >> numberQuestion[0];
answerCountDown();
}
// if the answer is correct
if (numberQuestion[0] == 1972) {
// answer countdown like a drumroll
randomNumbers();
correctAnswer();
rightAnswer(rightQuestion);
rightQuestion= rightQuestion+1;
sleep (2);
askedAlready[0] = askedAlready[0] +1;
}
// if they get the answer wrong
else {
incorrectAnswer();
sleep (2);
}
break;
// if question was asked already then don't ask it again
case 2:
First off, be sure to use code tags like this: //Hello, world
Now, aside form the fact that you're using plenty of unnecessary code and arrays of ints where bools would work better, you should really only seed the random number generator once at the start of the main. Seeding it more could cause the error you're having.