-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplecalc.cpp
More file actions
37 lines (33 loc) · 1014 Bytes
/
simplecalc.cpp
File metadata and controls
37 lines (33 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
int main() {
float a,b;
char calc;
cout << "Enter first number: "<<endl;
cin >> a;
cout << "Enter an operation (+, -, *, /): "<<endl;
cin >> calc;
cout << "Enter second number: "<<endl;
cin >> b;
switch (calc) {
case '+':
cout << " Addition of " <<a<<" and "<<b<<" is: "<<a + b << endl;
break;
case '-':
cout << " Subtraction of " <<a<<" and "<<b<<" is: "<<a - b << endl;
break;
case '*':
cout << " Multiplication of " <<a<<" and "<<b<<" is: "<<a * b << endl;
break;
case '/':
if (b!= 0)
cout << " Division of " <<a<<" and "<<b<<" is: "<<a / b << endl;
else
cout << "Error: Division by zero!" << endl;
break;
default:
cout << "Error: Invalid Operation!" << endl;
break;
}
return 0;
}