Created
September 30, 2025 10:55
-
-
Save juanfal/194785c871d6fec46db4be29ce1cb66c to your computer and use it in GitHub Desktop.
calculator
This file contains hidden or 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
// 03.calculator.cpp | |
// juanfc 2025-09-30 | |
// | |
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int main() | |
{ | |
float a, b, r; | |
char op; | |
cout << "Enter 2 numbers: " << endl; | |
cin >> a >> b; | |
cout << "Enter a char for the operation: (+-*/): "; | |
cin >> op; | |
if (op == '+') { | |
r = a + b; | |
} else if (op == '-') { | |
r = a - b; | |
} else if (op == '*') { | |
r = a * b; | |
} else if (op == '/') { | |
r = a / b; | |
} else if (op == '^') { | |
r = pow(a, b); | |
} else { | |
cout << "Error: wrong operation, only +-*/^" << endl; | |
r = 0; | |
} | |
cout << a << " " << op << " " << b << " -> " << r << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment