Text-Based Quiz App with File-Based Questions
Build a quiz game in C++ for the terminal: it loads multiple-choice questions from a text file, asks them one at a time with a countdown for each, and at the end shows your score overall and per category (for example 4/5 in geography, 2/5 in history). Anyone can write new quizzes by editing the question file, and the program checks the file for mistakes and points to the exact line. Questions and answers can be shuffled, so each game is different. It's a good first C++ project: you'll learn structs and std::vector, reading and parsing files with fstream and getline, validating input, measuring time with std::chrono, shuffling with <random>, and testing.
- Estimate
- ~7.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
fstream · chrono
Project roadmap
- 01
Design the question file
~1hWrite README.md with the file format: each question is a block with a category line, a question line, 2 to 5 choice lines, and an answer line (the letter of the correct choice), separated by blank lines. Create a Question struct with the category, text, choices (a std::vector<std::string>) and the index of the correct answer. Write a sample file with at least 10 questions in 3 categories. Done when: README.md and the sample file are written.
- 02
Parse the file
~1.5hRead the file line by line with std::getline, building a Question from each block, and check it: all parts present, between 2 and 5 choices, and an answer letter matching a choice. When something is wrong, stop with a message giving the line number and the problem. Done when: the sample loads, and a broken file reports the exact line.
- 03
Run the quiz
~1.5hShow each question with its choices labeled A, B, C and so on, read the answer, accept upper or lower case, and re-ask on invalid input. Say whether the answer was right, showing the correct one when it wasn't. Add options to shuffle the questions and the choices (with std::shuffle and a seeded std::mt19937, keeping track of the correct answer), and to limit the number of questions. Done when: a full quiz can be played, with and without shuffling.
- 04
Add a timer
~1hMeasure the time each answer takes with std::chrono::steady_clock. If it takes longer than the limit (for example 20 seconds, set by an option), count the answer as wrong even if it's correct, and say it was too late. Record each question's time. Done when: slow answers are counted as wrong, and the time is shown after each question.
- 05
Show the results
~1hAt the end, print the total score and percentage, a table of results per category, the average answer time, and the questions that were missed with their correct answers. Done when: the summary matches the answers given during the quiz.
- 06
Test it
~1.5hWrite tests (with doctest or Catch2) for the parser (a valid file, a missing answer, too many choices and an unknown answer letter), the answer checking after shuffling, and the per-category scoring. Done when: all tests pass.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack