-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05.1 (C++) Calculation by calculator by using switch statement.cpp
More file actions
67 lines (57 loc) · 2.24 KB
/
05.1 (C++) Calculation by calculator by using switch statement.cpp
File metadata and controls
67 lines (57 loc) · 2.24 KB
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
/// Calculation by calculator by using switch statement
#include <iostream>
using namespace std;
int main()
{
char choice;
float x, y, result, n=6;
cout<<" ----Calculation by calculator---- \n";
cout<<" Press '+': Addition for 2 numbers \n";
cout<<" Press '-': Subtraction for 2 numbers \n";
cout<<" Press '*': Multiplication for 2 numbers \n";
cout<<" Press '/': Division for 2 numbers \n";
cout<<" Enter your choice: ";
cin>>choice;
switch(choice){
case '+':
cout<<"\n Enter number x & y are: ";
cin>>x>>y;
result=x+y;
cout<<" The [+] result is: "<<result<<endl;
break;
case '-':
cout<<"\n Enter number x & y are: ";
cin>>x>>y;
result=x-y;
cout<<" The [-] result is: "<<result<<endl;
break;
case '*':
cout<<"\n Enter number x & y are: ";
cin>>x>>y;
result=x*y;
cout<<" The [*] result is: "<<result<<endl;
break;
case '/':
cout<<"\n Enter number x & y are: ";
cin>>x>>y;
result=x/y;
cout<<" The [/] result is: "<<result<<endl;
break;
default:
cout<<"\n Choose your calculation option! \n\n";
break;
}
return 0;
}
/* ===== Output / Result:
Input:___________________________________
----Calculation by calculator----
Press '+': Addition for 2 numbers
Press '-': Subtraction for 2 numbers
Press '*': Multiplication for 2 numbers
Press '/': Division for 2 numbers
Enter your choose: *
Enter number x & y are: 5 6
Output:__________________________________
The [*] result is: 30.00
*/