Skip to content

Commit

Permalink
Merge pull request #10 from vaidyasen/main
Browse files Browse the repository at this point in the history
Simple calculator using switch statement
  • Loading branch information
NightHack36 authored Oct 20, 2021
2 parents 4af211e + 3731b4a commit 068823e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions C++ Code/c.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
// simple calculator

# include <iostream>
using namespace std;

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

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

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

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

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

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

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

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

return 0;
}

0 comments on commit 068823e

Please sign in to comment.