I have to make a quiz in c++ and my teacher said that i must do it by a text file. He told me to put the questions with the answers in the same file or a different file and let the program chose the question and the correct answer from the text file. As a beginner i don't know how to do it, some lines of code could be usefull if you could help me.
first, lets design that text file.
something like this might work:
Q1 4 What is the capital of the USA?
A1 0 Yo Mamma
A2 1 Washington DC
A3 0 Tennesse
A4 0 All of the above
so as you read that in, you have made it easy for yourself: all the lines are the same format of what it is (2 chars: question or answer with a number if you want it, could extend number past 1 digit if you want to with a little extra logic), a boolean (is this the correct answer?), and free form text until the end of the line. now you can ask the question, display the answers, and see if the user typed in the answer that is marked true.
this begs a class/struct to hold this info ... can you take it from here?
struct question
{
int question_number; //do you need it? could use to shuffle or randomly pick a subset etc
string question_text;
vector answer_text(10); //how many answers do you want to support here...?
int correct_answer_number; //which answer is right?
//what else might you want?
};
vector<question> quiz; //populate this in a file reading loop.