Advertisement
ivanwidyan

Simple Calculator With 2 Input and Using Functions

Oct 18th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int Add(int, int);
  5. int Substract(int, int);
  6. int Multiply(int, int);
  7. int Divide(int, int);
  8.  
  9. int main() {
  10.     int firstnum, secondnum;
  11.     char arithmetic_operations;
  12.  
  13.     cout << "Enter first number: ";
  14.     cin >> firstnum;
  15.  
  16.     cout << "Enter second number: ";
  17.     cin >> secondnum;
  18.  
  19.     cout << "Enter Arithmetic Operations (+, -, *, /): ";
  20.     cin >> arithmetic_operations;
  21.  
  22.     if (arithmetic_operations == '+')
  23.         cout << firstnum << " + " << secondnum << " = " << Add(firstnum, secondnum) << endl;
  24.     else if (arithmetic_operations == '-')
  25.         cout << firstnum << " - " << secondnum << " = " << Substract(firstnum, secondnum) << endl;
  26.     else if (arithmetic_operations == '*')
  27.         cout << firstnum << " * " << secondnum << " = " << Multiply(firstnum, secondnum) << endl;
  28.     else if (arithmetic_operations == '/')
  29.         cout << firstnum << " / " << secondnum << " = " << Divide(firstnum, secondnum) << endl;
  30.     else
  31.         cout << "You typed an invalid arithmetic operations!\n";
  32.     return 0;
  33. }
  34.  
  35. int Add(int firstnum, int secondnum) {
  36.     return firstnum + secondnum;
  37. }
  38.  
  39. int Substract(int firstnum, int secondnum) {
  40.     return firstnum - secondnum;
  41. }
  42.  
  43. int Multiply(int firstnum, int secondnum) {
  44.     return firstnum * secondnum;
  45. }
  46.  
  47. int Divide(int firstnum, int secondnum) {
  48.     return firstnum / secondnum;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement