-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#22 calculator.cpp
48 lines (38 loc) · 975 Bytes
/
#22 calculator.cpp
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
38
39
40
41
42
43
44
45
46
47
48
/* Q)Write a C++ program that performs the operations of a
standard calculator (+,-,*,/,%). The user should enter two
operands and an arithmetic operator. According to these inputs,
the result of the operation should be displayed on the screen. */
#include<iostream>
using namespace std;
int main()
{
int num1, num2;
char op; /* op stands for operator, eg: +,-,etc. */
cout<<"Enter 1st number: ";
cin>>num1;
cout<<"Enter operator(+,-,*,/,%): ";
cin>>op;
cout<<"Enter 2nd number: ";
cin>>num2;
switch(op)
{
case '+':
cout<<num1<<op<<num2<<" = "<<num1+num2;
break;
case '-':
cout<<num1<<op<<num2<<" = "<<num1-num2;
break;
case '*':
cout<<num1<<op<<num2<<" = "<<num1*num2;
break;
case '/':
cout<<num1<<op<<num2<<" = "<<num1/num2;
break;
case '%':
cout<<num1<<op<<num2<<" = "<<num1%num2;
break;
default:
cout<<"Wrong Choice";
}
return 0;
}