Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int x;
  6. int y;
  7. int d;
  8. string op;
  9. int answer;
  10.  
  11. int calc (string op, int x, int y) {
  12.  
  13. if (op == "Mult" || "mult" || "MULT"){
  14.  d = x * y;
  15. }else if (op == "Div" || "div" || "DIV"){
  16.  d = x / y;
  17. }else if (op == "Add" || "add" || "ADD"){
  18.  d = x + y;
  19. }else if (op == "Sub" || "sub" || "SUB"){
  20.  d = x - y;
  21. }else{
  22. cout << "Error";
  23. }
  24. return d;
  25. }
  26.  
  27. void printanswer() {
  28. answer = calc(op, x, y);
  29. cout << "Answer:" << answer;
  30. cout << "Parameters: " << op << x << y;
  31. }
  32.    
  33.        
  34. int main() {
  35. cout << "What Operation? (Mult, Div, Sub, Add)";
  36. cin >> op;
  37. cout << "First Number?";
  38. cin >> x;
  39. cout << "Second Number?";
  40. cin >> y;
  41. printanswer();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement