+ 1

What is the most easy way to make a calculator in c++

29th Sep 2017, 4:27 PM
Luka Pavčnik
Luka Pavčnik - avatar
2 Respostas
+ 18
#include <iostream> using namespace std; int main() { double num1 = 0.0; double num2 = 0.0; short select = 0; cout << "first num: "; cin >> num1; cout << "second num: "; cin >> num2; cout << "Select operation.\n"; cout << "1)Addition 2)Subtraction 3)Multiplication 4)Division\n"; cin >> select; switch (select) { case 1: cout << num1 + num2; break; case 2: cout << num1 - num2; break; case 3: cout << num1 * num2; break; case 4: cout << num1 / num2; break; default: cout << "Invalid operation!"; } }
29th Sep 2017, 4:39 PM
Babak
Babak - avatar
+ 15
for four main operations + - * /, the easiest way IMO is using the switch statement.
29th Sep 2017, 4:50 PM
Babak
Babak - avatar