I am making a trivia game and I am having some issues with a loop in it. When it runs it show all answers are right. The game is based on a 3 strike system, you get three strikes and the games over and it awards 1 point for each right answer. What am I missing? I am new to programming and haven't run into a problem like this to troubleshoot. I am using a parallel array to read in all the questions and chioces. An everything is working except getting it to distinguish between the right and wrong answers. Thanks in advance for any advise.
Code:
int triviaGame(int score)
{
char answer;
char correct;
int i = 0;
int strike = 0;
score = 0;
string Questions[46];
string optionA[46];
string optionB[46];
string optionC[46];
string optionD[46];
string question;
ifstream questIn;
ifstream aIn;
ifstream bIn;
ifstream cIn;
ifstream dIn;
questIn.open("Questions.txt");
aIn.open("OptionA.txt");
bIn.open("OptionB.txt");
cIn.open("OptionC.txt");
dIn.open("OptionD.txt");
while(questIn && i < 45)
{
i++;
getline(questIn,Questions[i]);
}
i = 0;
while(aIn && i < 45)
{
i++;
getline(aIn,optionA[i]);
}
i = 0;
while(bIn && i < 45)
{
i++;
getline(bIn,optionB[i]);
}
i = 0;
while(cIn && i < 45)
{
i++;
getline(cIn,optionC[i]);
}
i = 0;
while(dIn && i < 45)
{
i++;
getline(dIn,optionD[i]);
}
do
{
i = rand() % 45;
cout << Questions[i] << endl
<< endl
<< optionA[i] << " " << optionB[i] << endl
<< optionC[i] << " " << optionD[i] << endl
<< endl
<< "What is your answer?" << endl
<< endl;
cin >> answer;
if( i = 5 || 11 || 21 || 25 || 33 || 38 || 43 )
correct = 'a' || 'A';
else if( i = 2 || 3 || 7 || 9 || 20 || 22 || 24 || 30 || 36 || 39 || 41 || 42 || 45 )
correct = 'b' || 'B';
else if( i = 1 || 4 || 10 || 12 || 14 || 16 || 17 || 23 || 26 || 29 || 31 || 40 || 46 )
correct = 'c' || 'C';
else if( i = 6 || 15 || 18 || 27 || 32 || 35 || 37 )
correct = 'd' || 'D';
else if( i = 8 || 13 || 28 || 34 )
correct = 't' || 'T';
else
correct = 'f' || 'F';
if( answer = correct )
{
score = score + 1;
cout << "That's right, you get a point." << endl
<< endl;
}
if( answer != correct)
{
strike = strike + 1;
cout << "That's not the right answer. You get a strike." << endl
<< endl;
}
}while(strike < 3);
questIn.close();
aIn.close();
bIn.close();
cIn.close();
dIn.close();
return score;
}
Comment