-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCalculator.cpp
40 lines (34 loc) · 1.25 KB
/
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
#include<iostream>
using namespace std; //Declaring input/output operator as std
int main()
{
system("cls"); //To clear the screen
int a,b,c;
char ch;
cout<<"Enter the first value: ";
cin>>a;
cout<<"Enter the second value: ";
cin>>b;
opratr:
cout<<"Enter the operator(+, -, *, /): ";
cin>>ch;
switch(ch)
{
case '+' : c = a + b;
cout<<"\nThe sum of "<<a<<" and "<<b<<" is " <<c<<endl;
break;
case '-' : c= a - b;
cout<<"\nThe difference between "<<a<<" and "<<b<<" is "<<c<<endl;
break;
case '*' : c = a * b;
cout<<"\nThe product of "<<a<<" and "<<b<<" is "<<c<<endl;
break;
case '/' : c = a / b;
cout<<"\nThe quotient of "<<a<<" and "<<b<<" is "<<c<<endl;
break;
default : cout<<"\n\nWrong operator!\nEnter a valid one!\n"<<endl;
goto opratr; //goto function so the continuity of program doesn't break
}
system("pause"); //It is an function which holds the screen
return 0;
}