Advertisement
zachdyer

Command Line Simple Calculator

Dec 24th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[] ){
  7.    
  8.     int a = strtoul(argv[1],NULL,0);
  9.     string op = argv[2];
  10.     int b = strtoul(argv[3],NULL,0);
  11.     int answer = 0;
  12.    
  13.     if(op == "+"){
  14.         answer = a + b;
  15.     }
  16.     else if(op == "-"){
  17.         answer = a - b;
  18.     }
  19.     else if(op == "*"){
  20.         answer = a * b;
  21.     }
  22.     else if(op == "/"){
  23.         answer = a / b;
  24.     }
  25.    
  26.     cout << a << " " << op << " " << b << " = " << answer << endl;
  27.     //cout << op << endl;
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement