Source of compute.cpp


  1: //compute.cpp
  2: //Does simple arithmetic

  4: #include <iostream>
  5: #include <string>
  6: #include <cstring>
  7: using namespace std;


 10: int main(int argc, char* argv[])
 11: {
 12:     int i, result;
 13:     switch (argv[2][0])
 14:     {
 15:     case '+':
 16:         result = atoi(argv[1]) + atoi(argv[3]);
 17:         break;
 18:     case '-':
 19:         result = atoi(argv[1]) - atoi(argv[3]);
 20:         break;
 21:     case '*':
 22:         result = atoi(argv[1]) * atoi(argv[3]);
 23:         break;
 24:     case '/':
 25:         result = atoi(argv[1]) / atoi(argv[3]);
 26:         break;
 27:     }
 28:     cout << argv[1] << " " << argv[2] << " "
 29:         << argv[3] << " = " << result << endl;
 30: }