thats only example for the create a structure of information of the person ... but my problems is how to form that or to program compose a question and answer of the quest using structure ..
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
however,I assumed that your Output Sample File.txt is empty for now and your MyInFile.txt file containes these data
Chandler meyrial bing 30
ross something green 31
joy actor turbiani 32
1.) How many feet of the dog?
2.) How many feet of the check?
3.) How many feet of the snake?
The program load the whole name also the age of three know people ,then load a question ,ask it to the used ,the both quesion and answer are saved in the Output Sample File.txt file
my professor give me some tips .. the output it should be show all the answer after the quiz then, it will calculate the score of the quiz if he/she pass the quiz
Your professor showed you how to read the question and possible answers from the file. You also need to read the correct choice from the file and compare that choice to the users answer, then keep counters for the number of questions and the number of correct answers. Then you need to loop until you reach end of file.
Upon reaching end of file, you need to calculate and display the score.
You need to attempt to write the code yourself. We will help with questions, but we're not going to write it for you.
Sounds like you might be opening and closing the file inside your loop.
You need to open the input file before the loop and close the input file after the loop.
A separate function to read the question, possible answers and correct answer might simplify things.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct QandA;
{ string q;
string a,b,c,d;
char correct_ans;
};
bool getQandA (ifstream & in, QandA & qa)
{ getline (in, qa.q);
if (in.eof())
returnfalse; // no more questions
// read a,b,c,d
// read correct answer
returntrue; // Successfully got a question and answers
}
Now in main, you can simply loop on getQandA()
1 2 3 4 5 6 7 8 9 10 11 12 13 14
...
QandA qa;
// Open input
while (getQandA(in, qa))
{ // got good information in the struct
// prompt the user
// get the answer from the user
// compare the user's answer to the correct answer
// count if right or wrong
// write the result to the output file
} // end of loop
// calculate and display the score
// close the files