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
49 changes: 49 additions & 0 deletions CPP/calculator_cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// C++ program to create calculator using
// switch statement
#include <iostream>
using namespace std;

// Main program
main()
{
char op;
float num1, num2;

// It allows user to enter operator i.e. +, -, *, /
cin >> op;

// It allow user to enter the operands
cin >> num1 >> num2;

// Switch statement begins
switch (op) {

// If user enter +
case '+':
cout << num1 + num2;
break;

// If user enter -
case '-':
cout << num1 - num2;
break;

// If user enter *
case '*':
cout << num1 * num2;
break;

// If user enter /
case '/':
cout << num1 / num2;
break;

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

return 0;
}