Advertisement
Guest User

Act 7

a guest
Oct 9th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #pragma warning(disable: 4996)
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.  
  8. double operand1, operand2, answer;
  9. char operator;
  10. char charOperandBuffer;
  11.  
  12.  
  13. int scan;
  14.  
  15.  
  16. while (1) {
  17.  
  18.  
  19. scan = 0;
  20.  
  21.  
  22. scan += scanf("%lf", &operand1);
  23.  
  24.  
  25. if (scan == 0) {
  26.  
  27. charOperandBuffer = 0;
  28. scan += scanf("%c", &charOperandBuffer);
  29.  
  30.  
  31. switch (charOperandBuffer) {
  32. case 'p':
  33.  
  34. operand1 = answer;
  35. break;
  36. case 'q':
  37.  
  38. return(0);
  39. break;
  40. }
  41. }
  42.  
  43. scan += scanf(" %c", &operator);
  44. scan += scanf(" %lf", &operand2);
  45.  
  46.  
  47. if (scan == 3) {
  48.  
  49.  
  50. switch (operator) {
  51. case '+':
  52.  
  53. answer = operand1 + operand2;
  54. break;
  55.  
  56. case '-':
  57.  
  58. answer = operand1 - operand2;
  59. break;
  60.  
  61. case '*':
  62.  
  63. answer = operand1 * operand2;
  64. break;
  65.  
  66. case '/':
  67.  
  68.  
  69.  
  70. if (operand2 != 0) {
  71. answer = operand1 / operand2;
  72. }
  73. else {
  74.  
  75. printf("invalid output");
  76. return(0);
  77. }
  78. break;
  79.  
  80. default:
  81.  
  82. printf("invalid input\n");
  83. }
  84.  
  85.  
  86. printf("ANS = %f\n", answer);
  87.  
  88. }
  89. else {
  90.  
  91. printf("invalid input\n");
  92. }
  93.  
  94.  
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement