diff --git a/src/equation.cpp b/src/equation.cpp new file mode 100644 index 0000000..caace16 --- /dev/null +++ b/src/equation.cpp @@ -0,0 +1,25 @@ +#include "equation.h" +#include "logging.h" +#include + +int getRandomNumber(int min, int max) { + logInformation(1, "Generating random number with min: " + std::to_string(min) + " and max: " + std::to_string(max)); + return rand() % (max - min + 1) + min; +} + +void generateLinearEquation(int& a, int& b, int& c, int& correctAnswer) { + logInformation(1, "Generating linear equation..."); + a = getRandomNumber(1, 10); + correctAnswer = getRandomNumber(1, 10); + c = getRandomNumber(0, 10); + b = a * correctAnswer + c; +} + +void generateQuadraticEquation(int& a, int& b, int& c, int& d, int& correctAnswer) { + logInformation(1, "Generating quadratic equation..."); + a = getRandomNumber(1, 10); + correctAnswer = getRandomNumber(1, 10); + b = getRandomNumber(1, 10); + c = getRandomNumber(1, 10); + d = a * correctAnswer * correctAnswer + b * correctAnswer + c; +} diff --git a/src/logging.cpp b/src/logging.cpp new file mode 100644 index 0000000..30dbf65 --- /dev/null +++ b/src/logging.cpp @@ -0,0 +1,23 @@ +#include "logging.h" +#include + +bool debugMode = false; + +void logInformation(int level, const std::string& information) { + if (!debugMode) return; + + switch (level) { + case 1: + std::cout << "[INFO] " << information << "\n"; + break; + case 2: + std::cout << "[WARN] " << information << "\n"; + break; + case 3: + std::cout << "[ERROR] " << information << "\n"; + break; + default: + std::cout << "[INTERNAL-ERROR] Incorrect usage of logInformation()!\n"; + break; + } +} diff --git a/src/tui.cpp b/src/tui.cpp new file mode 100644 index 0000000..c3f1446 --- /dev/null +++ b/src/tui.cpp @@ -0,0 +1,68 @@ +#include "tui.h" +#include "equation.h" +#include "logging.h" +#include + +void displayMenu() { + std::cout << "Welcome to Extreme Math!\n"; + std::cout << "Please select an option:\n"; + std::cout << "1. Solve Linear Equations\n"; + std::cout << "2. Solve Quadratic Equations\n"; + std::cout << "3. Challenge Mode\n"; + std::cout << "4. Exit\n"; +} + +void solveLinear() { + int a, b, c, correctAnswer, userAnswer; + generateLinearEquation(a, b, c, correctAnswer); + std::cout << "Solve for x: " << a << "x + " << b << " = " << c << "\n"; + std::cout << "Your answer: "; + std::cin >> userAnswer; + + if (userAnswer == correctAnswer) { + std::cout << "Correct! Well done.\n"; + } else { + std::cout << "Wrong answer. The correct answer was: " << correctAnswer << "\n"; + } +} + +void solveQuadratic() { + int a, b, c, d, correctAnswer, userAnswer; + generateQuadraticEquation(a, b, c, d, correctAnswer); + std::cout << "Solve for x: " << a << "x^2 + " << b << "x + " << c << " = " << d << "\n"; + std::cout << "Your answer: "; + std::cin >> userAnswer; + + if (userAnswer == correctAnswer) { + std::cout << "Correct! Well done.\n"; + } else { + std::cout << "Wrong answer. The correct answer was: " << correctAnswer << "\n"; + } +} + +void playGame() { + char choice; + do { + displayMenu(); + std::cin >> choice; + + switch (choice) { + case '1': + solveLinear(); + break; + case '2': + solveQuadratic(); + break; + case '3': + solveLinear(); + solveQuadratic(); + break; + case '4': + std::cout << "Thanks for playing!\n"; + break; + default: + std::cout << "Invalid option. Please try again.\n"; + } + + } while (choice != '4'); +}