Skip to content

Repository files navigation

Math Game (CLI)

A structured, clean, and optimized Command Line Interface (CLI) Math Quiz game written in C++. The project is built following solid software engineering principles, such as the Single Responsibility Principle (SRP) and memory-efficient parameter passing.


🚀 Features

  • Dynamic Question Generation: Supports 3 difficulty levels (Easy, Med, Hard) and a Mix level.
  • Diverse Operations: Supports Addition, Subtraction, Multiplication, Division, and a Mix operations mode.
  • Memory Efficient: Uses pass-by-reference (const &) to eliminate unnecessary structural copying in memory.
  • Clean Code Architecture: Completely decouples game logic, UI rendering, and score tracking.
  • Interactive UI: Dynamic console coloring to give immediate visual feedback (Green for correct, Red with audio alert for incorrect).

🛠️ Architecture & Code Design

The application transitions from a monolithic structure to a highly modular architecture:

1. Data Structures

  • stQuestion: Encapsulates all data for a single question (operands, operation type, level, correct answer, player answer, and status).
  • stQuiz: Manages the overall session, including an array of questions, configuration, counters, and final status.

2. Core Modules

  • Generation Logic: GenerateQuestion() utilizes a unified switch-case system to handle bounds before evaluating the math expression via SimpleCalculator().
  • Input/Output Separation: AskQuestion() handles user IO exclusively, while IsRightAnswer() acts as a pure function to check results without side effects.
  • State Management: UpdateScore() updates session metrics cleanly using concise ternary expressions.

💻 Game Preview

How Many Questions Do you Want to Answer ? ->> 3
Enter Questions Level  { Easy = 1, Med = 2, Hard = 3, Mix = 4 } ->> 4
Enter Operation Type { Add = 1, Sub = 2, Mul = 3, Div = 4, Mix = 5 } ->> 5
Question [1/3].
48 / 39 = 1

Right Answer :)
---------------

Question [2/3].
57 + 49 = 106

Right Answer :)
---------------

Question [3/3].
434 - 207 = 227

Right Answer :)
---------------

                        --------------------------------------------------------------
                                                G a m e  O v e r
                        --------------------------------------------------------------
                        ----------------------[Quiz Results]--------------------------
                                                Passed ^_~
                        --------------------------------------------------------------
                        Number of Questions : 3
                        Questions Level : Mix
                        Operations Type : Mix +-*/
                        Number of Right Answers : 3
                        Number of Wrong Answers : 0
                        --------------------------------------------------------------

Do You want to play again ? [Y/N] :
----------------------------
image image

💻 Related Projects

If you'd like to explore more of my C++ journey and see how I build data structures, algorithms, and complete applications from scratch, check out these repositories.


📚 C++ Data Data Structures & Algorithms From Scratch

A collection of advanced Data Structures and Algorithms implemented completely from scratch in C++.

This repository contains:

  • Custom implementations of Linked List, Stack, Queue, Dynamic Array, String, and more.
  • Every data structure includes a dedicated test file (.cpp) with practical examples.
  • Multiple implementations of the same project to compare different approaches (Custom Data Structures vs STL).
  • Solutions and projects from Programming Advices – Algorithms & Problem Solving Level 5 course.

Most of these classes are extensions of the libraries available in MyCppToolboxLibraries.

https://github.com/yahiaalsebaie/CppDataStructuresFromScratch


🔧 MyCppToolboxLibraries

My personal C++ library built completely from scratch.

It contains reusable utility classes that I developed throughout my programming journey, including:

  • Date & Time
  • String
  • Input Validation
  • Utility Functions
  • Period
  • And many more...

Many of the projects below are built on top of these libraries.

https://github.com/yahiaalsebaie/MyCppToolboxLibraries


🏦 Bank System (OOP)

Object-Oriented implementation of a complete banking system.

Includes the Currency Exchange project.

https://github.com/yahiaalsebaie/Bank-System-OOP


🏦 Bank Management System (Procedural Programming)

The same banking system implemented using Procedural Programming.

https://github.com/yahiaalsebaie/Bank-Management-System-Cpp


🏧 ATM System

Complete ATM simulation.

https://github.com/yahiaalsebaie/ATM-System-Course08


📅 Dual Calendar System

Gregorian & Hijri Calendar Library.

Features:

  • Date calculations
  • Date arithmetic
  • Historical dates
  • Astronomical calculations
  • Date differences

https://github.com/yahiaalsebaie/Dual-Calendar-System-MiladiAndHijiri


🎮 Math Game

Console Math Game.

https://github.com/yahiaalsebaie/cpp-Math-Game


✂️ Stone Paper Scissors Game

Console implementation of the classic game.

https://github.com/yahiaalsebaie/stone-paper-scissors-cpp-game


⭐ If you find this repository useful...

Please consider giving it a ⭐.

It helps others discover the project and motivates me to continue improving it.

About

A modular C++ CLI Math Quiz game. Features dynamic question generation with varied difficulties and operations. Optimized via pass-by-reference and SRP. Developed as the 2nd project of the 5th course (Algorithms & Problem Solving L2) on the ProgrammingAdvices platform.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages