Untitled


SUBMITTED BY: Guest

DATE: May 21, 2013, 9 p.m.

FORMAT: Text only

SIZE: 1.1 kB

HITS: 990

  1. // Program which performs addition, subtraction, multiplication and subtraction.
  2. #include <iostream>
  3. using namespace std;
  4. // input function
  5. void Input (float &x, float &y);
  6. float a=1.0, b=1.0, result;
  7. char operation;
  8. int main ()
  9. {
  10. cout << "Program which performs addition, subtraction, multiplication and subtraction. \n\n";
  11. cout << "Please input calculation operation (eg. 1 + 2): \n";
  12. cin >> a >> operation >> b;
  13. Input (a,b);
  14. cout << "The answer is: " << result << endl;
  15. system ("pause");
  16. return 0;
  17. }
  18. void Input (float &x, float &y)
  19. {
  20. a = x;
  21. b = y;
  22. switch (operation)
  23. {
  24. case '+':
  25. result = x + y;
  26. break;
  27. case '-':
  28. result = x - y;
  29. break;
  30. case '*':
  31. result = x * y;
  32. break;
  33. case '/':
  34. result = x / y;
  35. break;
  36. default:
  37. cout << "Improper operation. Please input a correct calculation operation: \n";
  38. cin >> a >> operation >> b;
  39. Input (a, b);
  40. }
  41. }

comments powered by Disqus