Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /* File: rec_debug.c
  2. * By: connoryk
  3. * Team: JKC
  4. * Date: 4/18/18
  5. */
  6.  
  7. /* A file producing the correct output for problem 3c and d on the midterm
  8. DEBUG COPY
  9. */
  10.  
  11. #include <stdio.h>
  12.  
  13. int main() {
  14.  
  15. /* Initialize variables */
  16. int flag = 0;
  17. float distance = 0,
  18. prev_dist = 0,
  19. speed = 0,
  20. prev_speed = 0,
  21. spd_diff = 0;
  22.  
  23. printf("debug: program start\n");
  24.  
  25. /* Get first distance */
  26. scanf("%f", &distance);
  27.  
  28. /* Check if Zero*/
  29. while(distance == 0) {
  30. printf("debug1: its zero\n");
  31. scanf("%f", &distance);
  32. }
  33.  
  34. printf("debug1: past first loop\n");
  35.  
  36. /* While there are more distances */
  37. while(flag != EOF) {
  38.  
  39. printf("debug: within big loop\n");
  40.  
  41. printf("debug1: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
  42.  
  43. /* Cache distance */
  44. prev_dist = distance;
  45.  
  46. printf("debug2: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
  47.  
  48. /* Get next distance */
  49. flag = scanf("%f",&distance);
  50.  
  51. printf("debug3: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
  52.  
  53. /* in the case of zero */
  54. if(distance == 0) {
  55.  
  56. printf("debug:zerocase\n");
  57.  
  58. /* Get the indicator to cross or not cross */
  59. if(speed > 0) {
  60.  
  61. printf("Car: speed is %.2f MPH;", speed);
  62.  
  63. /* Compute speed difference */
  64. spd_diff = prev_speed - speed;
  65.  
  66. printf("debug_zerocase1: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
  67. printf("debug_zerocase1: speed_diff %.2f\n", spd_diff);
  68.  
  69. /* Set conditions for speed difference */
  70. if(spd_diff > 0 && speed <= 10) {
  71.  
  72. /* Safe to cross*/
  73. printf("Safe to cross \n");
  74. }
  75. else if(spd_diff < 0 || speed > 10) {
  76. printf("DO NOT STEP OFF THE CURB! \n");
  77. }
  78.  
  79. /* Update speeds */
  80. prev_speed = speed = 0;
  81.  
  82. /* Update distances */
  83. prev_dist = distance = 0;
  84.  
  85. /* Get next distance */
  86. scanf("%f",&prev_dist);
  87.  
  88. /* Check if Zero*/
  89. while(prev_dist == 0){
  90. scanf("%f", &prev_dist);
  91. }
  92. }
  93. }
  94.  
  95. /* Common Case */
  96. else if(distance != 0) {
  97.  
  98. printf("debug_comm case: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
  99. /* Update previous speed */
  100. prev_speed = speed;
  101.  
  102. printf("debug_comm case1: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
  103. /* Compute Speed */
  104. speed = ((prev_dist - distance) / 5280) * 3600;
  105.  
  106. printf("debug_comm case2: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
  107. }
  108. }
  109.  
  110. printf("\ndebug: end of file\n");
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement