'It is OK if my code is fragile and dependent on the line numbers of that specific file."
It's not okay. We're not okay with it. Ugly code leads to bugs, problems, and headaches - plus, whenever you're asking for help you should treat others with respect and provide the best you can.
Secondly, whenever you see something like this:
1 2 3 4
|
string answerOne;
string answerTwo;
string answerThree;
string answerFour;
|
think twice. Why not just use:
string answers[4];
This even plays better with your "correct answer":
1 2
|
if(inputted_answer == answers[correct_answer])//or correct_answer-1, if we index from 1...
//do something.
|
Code quality doesn't collide with knowledge. If you know that you write something bad, you can fix it, without waiting for some arbitrary timepoint.
Now that I look at your code, it's even more terrible; see this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
if (lineN < 7)
{
cout << line << endl;
ques[0].setTriviaQuestion(line); //Question 1
ques[0].setAnswerOne(line);
ques[0].setAnswerTwo(line);
ques[0].setAnswerThree(line);
ques[0].setAnswerFour(line);
}
else if (lineN == 7)
{
ques[0].setCorrectAnswer(correctA);
ques[0].checkGivenAnswer(player1A);
}
else if (lineN > 7 && lineN < 14)
{
cout << line << endl;
ques[1].setTriviaQuestion(line); //Question 2
ques[1].setAnswerOne(line);
ques[1].setAnswerTwo(line);
ques[1].setAnswerThree(line);
ques[1].setAnswerFour(line);
}
|
I can already see the pattern. It's all over there. Whenever you copy-paste your own code, it's a bad sign. This one is a really bad code. You want to use a for loop. You could do something like this(pseudocode incoming):
1 2 3 4 5 6
|
int questionNum = 0;
while(NextChar != End Of File)
{
SetQuestion();
++questionNum;
}
|
SetQuestion could be the body of first two ifs in your for loop. Look that it is far more concise, and it's obvious what's happening.
The better(clearer) code you write, the less bugs you make(because it's easier to find them). Please rewrite your code, so that numbers are in form of numbers, not words(questions[], not questionOne, questionTwo,... ; getQuestion(int), not getQuestionOne, getQuestionTwo,...).
This is called "refactoring" - you're rewriting the code to look better, or work better(or both). Please do so and update your code. Then it will be easier to help you.