forked from pranavgoel29/CPP-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_Calculator.cpp
60 lines (57 loc) · 1.62 KB
/
4_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
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
system("cls");
char ch;
float a, b, c, i;
cout<<"CALCULATOR!"<<endl;
{
denominator:
cout<<"\nEnter first value: ";
cin>>a;
cout<<"Enter the second value: ";
cin>>b;
op:
cout<<"Enter an operator(+, -, *, /, %): ";
cin>>ch;
switch(ch)
{
case '+': c = a+b;
cout<<"\nThe sum of the given value is "<<c<<endl;
break;
case '-': c = a-b;
cout<<"\nThe difference between the given value is "<<c<<endl;
break;
case '*': c = a*b;
cout<<"\nThe product of the given value is "<<c<<endl;
break;
case '/': if(b == 0)
{
cout<<"\nThe denominator cannot be zero."<<endl;
goto denominator;
}
else
c= a/b;
cout<<"\nThe quotient of the given value is "<<c<<endl;
break;
case '%': if((int)b==0)
{
cout<<"\nThe denominator cannot be zero."<<endl;
goto denominator;
}
else
{
c= (int)a % (int)b;
cout<<"\nThe remainder of the given value is "<<c<<endl;
break;
}
default: cout<<"\nYou entered an invalid operator!"<<endl;
cout<<"Please choose an valid operator!\n"<<endl;
goto op;
}
}
getch();
return 0;
}