diff options
| author | jstmax! <87650746+MaxWasTakenYT@users.noreply.github.com> | 2024-10-17 18:40:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-17 18:40:07 +0000 |
| commit | b21cb476c60953a8a361ca74659d6f4d35d112bb (patch) | |
| tree | d49a070f4688966e1c4efbeb27f2ef7b6d08f930 /xsc.cpp | |
| parent | f9670154f9fb79bb6b466295c73b3f6b6888bb89 (diff) | |
Update and rename xsc_debug.cpp to xsc.cpp
Diffstat (limited to 'xsc.cpp')
| -rw-r--r-- | xsc.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -0,0 +1,76 @@ +#include <iostream> +#include <string> +#include <cmath> +using namespace std; + +void usage() { + // Prints usage message (help) + system("figlet XSC | lolcat"); + cout << "\neXtremelySimpleCalculator usage:\n" + << "`xsc --help | -h` for help\n" + << "`xsc <number> <(+|-|*|/|%|^)> <number>` for mathematical operation\n" + << "`xsc -sqrt | -r <number>` for square root operation\n" + << "\n[n!] `xsc` doesn't support mathematical expressions (to-do)\n"; +} + +int main(int argc, char* argv[]) { + // AAAAAAAAAA (a.k.a. argument validation and execution) + for (int i = 1; i < argc; ++i) { + string arg = argv[i]; + + if (arg == "--sqrt" || arg == "-r") { + } + else if (arg == "--help" || arg == "-h") { + usage(); + return 0; + } + else if (i + 2 < argc) { + string op = argv[i + 1]; + double num1 = stod(argv[i]); + double num2 = stod(argv[i + 2]); + double result; + + if (op == "+") { + result = num1 + num2; + } + else if (op == "-") { + result = num1 - num2; + } + else if (op == "*") { + result = num1 * num2; + } + else if (op == "/") { + if (num2 != 0) { + result = num1 / num2; + } + else { + cout << "[math_e!] division by zero!\n"; + usage(); + return 1; + } + } + else if (op == "%") { + result = fmod(num1, num2); + } + else if (op == "^") { + result = pow(num1, num2); + } + else { + cout << "[e!] invalid operator!\n"; + usage(); + return 1; + } + // show result :) + cout << result << "\n"; + return 0; + } + else { + cout << "[e!] invalid input!\n"; + usage(); + return 1; + } + + } + + return 0; +} |