saving progress of a user in quiz game

I'm making a quiz game in c++. I've already completed it. But now I've thought of creating a profile and saving the progress for the user so when he enters his name the game continues frm where he had saved it. I would really appreciate some help on this one. Thank you!
I think the best place to start would be just saving it to a simple text file. There is a great tutorial on this website if you still haven't dealt with files yet in C++.

All you would need to do is write the stats to a file when the game ends (When the program exits) to save them. And then read from that file (If it is there at the time) at the start of your program to load in the previous stats. The tutorial above will give you everything you need to know to come up with a solution to do this.

Otherwise if you are looking for some a bit more mainstream and advanced you can look into serialization. You could use standard formats like XML and Json (Libraries included below) or create your own binary format.

XML - For XML I love using TinyXML2 since it has a very small footprint, is quite fast and is very easy to use.

Json - I haven't used Json much but have heard good things about this parser.

Then of course there is always boost which has plenty of tools for serialization.
Thnx a lot. I will try this stuff. Will contact u if any problem arises. Really appreciate ur help. Thnx again.
You could make yourself a text based relational database using a CSV format:

1,What is 10 times 10,100
2,What is 10 times 20,200


Say John logs in and we want to know his progress Look up his name in users.csv and find his id. Then collect all of the lines in user_questions.csv where the value in the user_id column is equal to John's id. These are the questions he has answered. You can use this list to find questions he has not answered in questions.csv.

So you basically need 4 classes here, User, Question, UserQuestion, and a class to read and manipulate a csv file.

For example, Sarah logs in. Her id can't be found in user_questions.csv, so she hasn't answered any questions. We retrieve a list of all of the questions, and offer them to her to answer. Say she answers question 1 with 100, which is correct. We add a line to user_questions.csv "2,2,1,true". The first 2 is the id of the UserQuestion, it is a new entry, so it gets an id one greater than the last entry. The second two is Sarah's id. The one is the id of the question, and the true is the fact that she got it correct.

This set up is pretty powerful. For example, with this data you can get information like "what percentage of users got question 1 correct?".
Topic archived. No new replies allowed.