Created
February 21, 2024 12:46
-
-
Save grayed/7485dce04efb72a044b6e1e89cb05979 to your computer and use it in GitHub Desktop.
КМБО-07-23 калькулятор со string
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
#include <cmath> | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
float calc(string op, float x, float y); | |
int main() { | |
float x, y, res; | |
char op, c = '1', arr[] = "123456789"; | |
string ops; | |
cout << "Enter x: "; | |
cin >> x; | |
cout << "Enter operation: "; | |
cin >> ops; | |
cout << "Enter y: "; | |
cin >> y; | |
res = calc(ops, x, y); | |
cout << "x " << ops << " y = " << res << endl; | |
return 0; | |
} | |
float calc(string op, float x, float y) { | |
float res; | |
if (op == "+") | |
res = x + y; | |
else if (op == "-") | |
res = x - y; | |
else if (op == "*") | |
res = x * y; | |
else if (op == "/") | |
res = x / y; | |
else if (op == "ln") | |
res = log(x) / log(y); | |
else { | |
cerr << "Unsupported operation: '" << op << "'\n"; | |
exit(1); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment