Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. /* File: recovery.c (rec.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.  
  9. #include <stdio.h>
  10.  
  11. int main() {
  12.  
  13. /* Initialize variables */
  14. int flag = 0;
  15. float distance = 0,
  16. prev_dist = 0,
  17. speed = 0,
  18. prev_speed = 0,
  19. spd_diff = 0;
  20.  
  21. printf("debug: program start\n");
  22.  
  23. /* Get first distance */
  24. scanf("%f", &distance);
  25.  
  26. /* Check if Zero*/
  27. while(distance == 0) {
  28.  
  29. scanf("%f", &distance);
  30. }
  31.  
  32. /* While there are more distances */
  33. while(flag != EOF) {
  34.  
  35. /* Cache distance */
  36. prev_dist = distance;
  37.  
  38. /* Get next distance */
  39. flag = scanf("%f",&distance);
  40.  
  41. /* in the case of zero */
  42. if(distance == 0) {
  43.  
  44. /* Get the indicator to cross or not cross */
  45. if(speed > 0) {
  46.  
  47. printf("Car: speed is %.2f MPH; ", speed);
  48.  
  49. /* Compute speed difference */
  50. spd_diff = prev_speed - speed;
  51.  
  52. /* Set conditions for speed difference */
  53. if(spd_diff > 0 && speed <= 10) {
  54.  
  55. /* Safe to cross*/
  56. printf("Safe to cross \n");
  57. }
  58.  
  59. else if(spd_diff < 0 || speed > 10) {
  60. printf("DO NOT STEP OFF THE CURB! \n");
  61. }
  62.  
  63. /* Update speeds */
  64. prev_speed = speed = 0;
  65.  
  66. /* Update distances */
  67. prev_dist = distance = 0;
  68.  
  69. /* Get next distance */
  70. scanf("%f",&prev_dist);
  71.  
  72. /* Check if Zero*/
  73. while(prev_dist == 0){
  74. scanf("%f", &prev_dist);
  75. }
  76. }
  77. }
  78.  
  79. /* Common Case */
  80. else if(distance != 0) {
  81.  
  82. /* Update previous speed */
  83. prev_speed = speed;
  84.  
  85. /* Compute Speed */
  86. speed = ((prev_dist - distance) / 5280) * 3600;
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement