-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitch_case_calclator.cpp
65 lines (49 loc) · 1.58 KB
/
Switch_case_calclator.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
// A small calculator
#include <iostream>
using namespace std;
int main()
{
int choice;
double a, b, c;
do
{
cout<<"Press 1 to Do the addition of two number\n";
cout<<"Press 2 to Do the subtraction of two number\n";
cout<<"Press 3 to Do the multiplication of two number\n";
cout<<"Press 4 to Do the division of two number\n";
cin >> choice;
if(choice <= 4)
{
cout<<"Enter the first number\n";
cin>>a;
cout<<"enter the second number\n";
cin>>b;
}
switch(choice)
{
case 1:
c = a + b;
cout<<"The Addition of\t"<<a<<"\tand\t"<<b<<"\tis\t"<<c<<endl;
cout<<"***********************************************\n";
break;
case 2:
c = a - b;
cout<<"The subtraction of"<<" "<<a<<"and"<<" "<<b<<"is"<<" "<<c<<endl;
cout<<"*********************************\n";
break;
case 3:
c = a * b;
cout<<"The Multiplication of"<<" "<<a<<"and"<<" "<<b<<"is"<<" "<<c<<endl;
cout<<"*********************************\n";
break;
case 4:
c = a / b;
cout<<"The Division of"<<" "<<a<<"and"<<" "<<b<<"is"<<" "<<c<<endl;
cout<<"*********************************\n";
break;
default:
cout<<"Enter a valid choice. Please choose again\n";
}
}while (choice != 4);
return 0;
}