forked from abhijithshaji17/cpp-mastery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.cpp
More file actions
40 lines (40 loc) · 965 Bytes
/
Copy path13.cpp
File metadata and controls
40 lines (40 loc) · 965 Bytes
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
// calculator switchcase program
#include<iostream>
using namespace std;
int main(){
int op;
double n1,n2,ans;
cout<<"----Menu Driven Calculator----\n";
cout<<"Enter the first number: ";
cin>>n1;
cout<<"Enter the second number: ";
cin>>n2;
cout<<"Select the desired operation below:\n";
cout<<"1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n";
cin>>op;
switch(op){
case 1:
ans=n1+n2;
cout<<"Sum = "<<ans;
break;
case 2:
ans=n1-n2;
cout<<"Difference = "<<ans;
break;
case 3:
ans=n1*n2;
cout<<"Product = "<<ans;
break;
case 4:
if(n2!=0){
ans=n1/n2;
cout<<"Quotient = "<<ans;
}else{
cout<<"Error: division by zero!";
}
break;
default:
cout<<"Invalid choice.";
}
return 0;
}