+ 1
What is the most easy way to make a calculator in c++
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!";
}
}
+ 15
for four main operations + - * /, the easiest way IMO is using the switch statement.