-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.cpp
60 lines (60 loc) · 932 Bytes
/
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
49
50
51
52
53
54
55
56
57
58
59
60
//write a programme to implement a calculator
#include<iostream>
using namespace std;
void add();
void sub();
void mul();
void div();
int a,b,c,y=1,ch,d;
int main()
{
while (y==1)
{
cout<<"enter values of a and b";
cin>>a>>b;
cout<<"the calculator operations are 1) addition \t 2) subtraction \t3)multiplication \t4)division "<<endl;
cout<<"choose one operation"<<endl;
cin>>ch;
do{
switch(ch)
{
case 1:
add();
break;
case 2:
sub();
break;
case 3:
mul();
break;
case 4:
div();
break;
case 5:
exit(0);
}
cout<<"do you want to continue? if yes press 1 else press 2";
cin>>d;
}while(d==1);
}
}
void add()
{
int c=a+b;
cout<<"sum is"<<c;
}
void sub()
{
int c=a-b;
cout<<"difference is"<<c;
}
void mul()
{
int c=a*b;
cout<<"product is"<<c;
}
void div()
{
int c=a/b;
cout<<"quotient is"<<c;
}