-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76d738
commit 1e957f5
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "equation.h" | ||
#include "logging.h" | ||
#include <cstdlib> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "logging.h" | ||
#include <iostream> | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "tui.h" | ||
#include "equation.h" | ||
#include "logging.h" | ||
#include <iostream> | ||
|
||
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'); | ||
} |