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:

if (askedAlready[1] <1){

secondQuestion();

cin >> questionAnswer[0];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[0] == "Mr.Figueira" || questionAnswer[0] == "mr.figueira" ||questionAnswer[0]== "mr.Figueira" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[1] = askedAlready[1]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

// if question was asked already then don't ask it again

case 3:

if (askedAlready[2] <1){

thirdQuestion();

cin >> questionAnswer[1];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[1] == "Rugby" || questionAnswer[1] == "rugby" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[2] = askedAlready[2]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 4:

// if question was asked already then don't ask it again

if (askedAlready[3] <1){

fourthQuestion();

cin >> numberQuestion[1];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[1] == 2011 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[3] = askedAlready[3]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 5:

// if question was asked already then don't ask it again

if (askedAlready[4] <1){

fifthQuestion();

cin >> questionAnswer[2];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[2] == "Mr.Johnston" || questionAnswer[2] == "mr.johnston" || questionAnswer[2] == "Mr.johnston" || questionAnswer[2] == "mr.Johnston") {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[4] = askedAlready[4]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 6:

// if question was asked already then don't ask it again

if (askedAlready[5] <1){

sixthQuestion();

cin >> questionAnswer[3];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[3] == "Millionaires" || questionAnswer[3] == "millionaires") {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[5] = askedAlready[5]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 7:

// if question was asked already then don't ask it again

if (askedAlready[6] <1){

seventhQuestion();

cin >> numberQuestion[2];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[2] == 1871 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[6] = askedAlready[6]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 8:

// if question was asked already then don't ask it again

if (askedAlready[7] <1){

eigthQuestion();

cin >> questionAnswer[4];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[4] == "Harper" || questionAnswer[4] == "harper" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[7] = askedAlready[7]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 9:

// if question was asked already then don't ask it again

if (askedAlready[8] <1){

ninthQuestion();

cin >> questionAnswer[5];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[5] == "Kurtenbach" || questionAnswer[5] == "kurtenbach" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[8] = askedAlready[8]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 10:

// if question was asked already then don't ask it again

if (askedAlready[9] <1){

tenthQuestion();

cin >> numberQuestion[3];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[3] == 1982 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

sleep (2);

askedAlready[9] = askedAlready[9]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

default: "please try again" ;

// end of switch

}

// end of while

}

return 0;

}

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:

if (askedAlready[1] <1){

secondQuestion();

cin >> questionAnswer[0];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[0] == "Mr.Figueira" || questionAnswer[0] == "mr.figueira" ||questionAnswer[0]== "mr.Figueira" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[1] = askedAlready[1]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

// if question was asked already then don't ask it again

case 3:

if (askedAlready[2] <1){

thirdQuestion();

cin >> questionAnswer[1];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[1] == "Rugby" || questionAnswer[1] == "rugby" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[2] = askedAlready[2]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 4:

// if question was asked already then don't ask it again

if (askedAlready[3] <1){

fourthQuestion();

cin >> numberQuestion[1];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[1] == 2011 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[3] = askedAlready[3]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 5:

// if question was asked already then don't ask it again

if (askedAlready[4] <1){

fifthQuestion();

cin >> questionAnswer[2];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[2] == "Mr.Johnston" || questionAnswer[2] == "mr.johnston" || questionAnswer[2] == "Mr.johnston" || questionAnswer[2] == "mr.Johnston") {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[4] = askedAlready[4]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 6:

// if question was asked already then don't ask it again

if (askedAlready[5] <1){

sixthQuestion();

cin >> questionAnswer[3];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[3] == "Millionaires" || questionAnswer[3] == "millionaires") {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[5] = askedAlready[5]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 7:

// if question was asked already then don't ask it again

if (askedAlready[6] <1){

seventhQuestion();

cin >> numberQuestion[2];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[2] == 1871 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[6] = askedAlready[6]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 8:

// if question was asked already then don't ask it again

if (askedAlready[7] <1){

eigthQuestion();

cin >> questionAnswer[4];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[4] == "Harper" || questionAnswer[4] == "harper" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[7] = askedAlready[7]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 9:

// if question was asked already then don't ask it again

if (askedAlready[8] <1){

ninthQuestion();

cin >> questionAnswer[5];

answerCountDown();

}

// if the answer is correct

if (questionAnswer[5] == "Kurtenbach" || questionAnswer[5] == "kurtenbach" ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

rightQuestion= rightQuestion+1;

sleep (2);

askedAlready[8] = askedAlready[8]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

case 10:

// if question was asked already then don't ask it again

if (askedAlready[9] <1){

tenthQuestion();

cin >> numberQuestion[3];

answerCountDown();

// if the answer is correct

}

if (numberQuestion[3] == 1982 ) {

// answer countdown like a drumroll

randomNumbers();

correctAnswer();

rightAnswer(rightQuestion);

sleep (2);

askedAlready[9] = askedAlready[9]+1;

}

// if they get the answer wrong

else {

incorrectAnswer();

sleep (2);

}

break;

default: "please try again" ;

// end of switch

}

// end of while

}

return 0;

}

First off, be sure to use code tags like this:

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.

`//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.

If you want help debugging this, post something that is compilable and USE CODE TAGS.

Topic archived. No new replies allowed.