Very good, you're getting there.
You should write all 5 cases of subject, and in each case (with the exception of the exit case), write the questions into (question into one line, answer into another line, next question in third line, answer in fourth and so on).
Then open the file, use a string (char s[50]), with getline(s,49), you can take the question into the string, which you can later display with puts(s) function. Then take the answer into an int variable. Then, test the entered value if it's the same as the answer, if yes, give points and display that he's correct, if wrong, don't give points, only display that he's wrong.
PS: HUGE THING TO WATCH OUT FOR: if you do this as I've said, you'll have a file like this:
1 2 3 4
|
How many weeks do we have in a year
52
How many days are in a week
7
|
When you take the int variable, the cursor will stand behind the number but BEFORE the newline, so using getline again will just take the enter, and everything messes up.
So this is how it should look like:
1 2 3 4 5 6 7 8 9 10 11
|
fstream f;
char question[100];
char empty[2];
int answer;
f.open("Questions.txt",ios::in);
while (!f.eof())
{
getline (question,99);
f>>answer;
getline (empty,1);
}
|