Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Calculator.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# include <iostream>
using namespace std;

int main()
{
char op;
float num1, num2;

cout << "Enter operator either + or - or * or /: ";
cin >> op;

cout << "Enter two operands: ";
cin >> num1 >> num2;

switch(op)
{
case '+':
cout << num1+num2;
break;

case '-':
cout << num1-num2;
break;

case '*':
cout << num1*num2;
break;

case '/':
cout << num1/num2;
break;

default:
// If the operator is other than +, -, * or /, error message is shown
cout << "Error! operator is not correct";
break;
}

return 0;
}