Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created September 30, 2025 10:55
Show Gist options
  • Save juanfal/194785c871d6fec46db4be29ce1cb66c to your computer and use it in GitHub Desktop.
Save juanfal/194785c871d6fec46db4be29ce1cb66c to your computer and use it in GitHub Desktop.
calculator
// 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