Advertisement
ivanwidyan

Calculator That Takes Four Arithmetic Operations as Input

Oct 16th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int firstnum, secondnum;
  6.     char arithmetic_operations;
  7.  
  8.     cout << "Enter first number: ";
  9.     cin >> firstnum;
  10.  
  11.     cout << "Enter second number: ";
  12.     cin >> secondnum;
  13.  
  14.     cout << "Enter Arithmetic Operations (+, -, *, /): ";
  15.     cin >> arithmetic_operations;
  16.    
  17.     if (arithmetic_operations == '+')
  18.         cout << firstnum << " + " << secondnum << " = " << firstnum + secondnum << endl;
  19.     else if (arithmetic_operations == '-')
  20.         cout << firstnum << " - " << secondnum << " = " << firstnum - secondnum << endl;
  21.     else if (arithmetic_operations == '*')
  22.         cout << firstnum << " * " << secondnum << " = " << firstnum * secondnum << endl;
  23.     else if (arithmetic_operations == '/')
  24.         cout << firstnum << " / " << secondnum << " = " << firstnum / secondnum << endl;
  25.     else
  26.         cout << "You typed an invalid arithmetic operations!\n";
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement