Guest User

Untitled

a guest
Oct 21st, 2019
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. #pragma warning(disable:4996)
  5. #ifndef __CHARCODES__
  6. #define __CHARCODES__
  7. #define INT_UPPER_BOUND 1001
  8. #define INT_LOWER_BOUND -1001
  9. #define VOODOO -1024
  10. #define ZERO 0
  11. #define MOD 5
  12. #endif
  13.  
  14. int main() {
  15. // initialize your variables...
  16. int int1;
  17. int int2;
  18. double sol;
  19. char opr;
  20. char sym;
  21. int typeCode = -1;
  22. //int1 prompt
  23. printf("Please enter a number between -1000 and 1000:\n");
  24. scanf("%d", &int1);
  25. rewind(stdin);
  26. //input parameters
  27. while (int1 <= INT_LOWER_BOUND || int1 >= INT_UPPER_BOUND) {
  28. printf("Yikes, why don't you try that again?\n\nPlease enter a number between -1000 and 1000:\n");
  29. scanf("%d", &int1);
  30. rewind(stdin);
  31. }
  32. //int2 prompt
  33. printf("Please enter another number between -1000 and 1000:\n");
  34. scanf("%d", &int2);
  35. rewind(stdin);
  36. //input parameters
  37. while (int2 != VOODOO && int2 <= INT_LOWER_BOUND || int2 >= INT_UPPER_BOUND) {
  38. printf("Yikes, why don't you try that again?\n\nPlease enter a number between -1000 and 1000:\n");
  39. scanf("%d", &int2);
  40. rewind(stdin);
  41. }
  42. //voodoo
  43. while (int2 == VOODOO) {
  44. printf("How did I know you would type 'negative one thousand and twenty four?'\n*tsk* *tsk* *tsk*\nNow why don't you try using a valid input?\n");
  45. scanf("%d", &int2);
  46. rewind(stdin);
  47. }
  48. //NO zeros!
  49. while (int2 == ZERO) {
  50. printf("No zeros allowed! Try that again:\n");
  51. scanf("%d", &int2);
  52. rewind(stdin);
  53. }
  54. //operator prompt
  55. printf("Choose an operation: (1 - 5)\n\n 1 : +\n 2 : -\n 3 : *\n 4 : /\n 5 : %%\n\n");
  56. scanf("%c", &opr);
  57. rewind(stdin);
  58. while (opr >= '6' || opr <= '0') {
  59. printf("Why don't you try using a valid input?\n");
  60. scanf("%c", &opr);
  61. rewind(stdin);
  62. }
  63. //Operator selection logic
  64. switch (opr) {
  65. case '1':
  66. sym = '+';
  67. sol = int1 + int2;
  68. break;
  69. case '2':
  70. sym = '-';
  71. sol = int1 - int2;
  72. break;
  73. case '3':
  74. sym = '*';
  75. sol = int1 * int2;
  76. break;
  77. case '4':
  78. sym = '/';
  79. sol = (double) int1 / int2;
  80. break;
  81. case '5':
  82. sym = '%';
  83. sol = int1 % int2;
  84. break;
  85. }
  86. //output
  87. printf("Here is your problem and its solution:\n\n %d %c %d = %4f\n\n ...press any key to exit", int1, sym, int2, sol);
  88. _getch();
  89. return 0;
  90. }
  91.  
  92. // answer the focus question
RAW Paste Data