-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge3.cpp
69 lines (59 loc) · 1.15 KB
/
challenge3.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
61
62
63
64
65
66
67
68
69
/*The following program should function as a basic calculator; it should ask the user to input what
type of arithmetic operation he would like, and then ask for the numbers on which the operation
should be performed. The calculator should then give the output of the operation.*/
#include <iostream>
int multiply(int x, int y)
{
return x*y;
}
int divide(int x, int y)
{
return x/y;
}
int add(int x, int y)
{
return x+y;
}
int subtract(int x, int y)
{
return x-y;
}
using namespace std;
int main()
{
char op='c';
int x, y;
while(op!='e')
{
cout<<"What operation would you like to perform: add(+), subtract(-), divide(/), multiply(*), [e]xit?";
cin>>op;
switch(op)
{
case '+':
cin>>x;
cin>>y;
cout<<x<<"+"<<y<<"="<<add(x, y)<<endl;
break;
case '-':
cin>>x;
cin>>y;
cout<<x<<"-"<<y<<"="<<subtract(x, y)<<endl;
break;
case '/':
cin>>x;
cin>>y;
cout<<x<<"/"<<y<<"="<<divide(x, y)<<endl;
break;
case '*':
cin>>x;
cin>>y;
cout<<x<<"*"<<y<<"="<<multiply(x, y)<<endl;
break;
case 'e':
break;
default:
cout<<"Sorry, try again"<<endl;
}
}
return 0;
}