Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* File: rec_debug.c
- * By: connoryk
- * Team: JKC
- * Date: 4/18/18
- */
- /* A file producing the correct output for problem 3c and d on the midterm
- DEBUG COPY
- */
- #include <stdio.h>
- int main() {
- /* Initialize variables */
- int flag = 0;
- float distance = 0,
- prev_dist = 0,
- speed = 0,
- prev_speed = 0,
- spd_diff = 0;
- printf("debug: program start\n");
- /* Get first distance */
- scanf("%f", &distance);
- /* Check if Zero*/
- while(distance == 0) {
- printf("debug1: its zero\n");
- scanf("%f", &distance);
- }
- printf("debug1: past first loop\n");
- /* While there are more distances */
- while(flag != EOF) {
- printf("debug: within big loop\n");
- printf("debug1: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
- /* Cache distance */
- prev_dist = distance;
- printf("debug2: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
- /* Get next distance */
- flag = scanf("%f",&distance);
- printf("debug3: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
- /* in the case of zero */
- if(distance == 0) {
- printf("debug:zerocase\n");
- /* Get the indicator to cross or not cross */
- if(speed > 0) {
- printf("Car: speed is %.2f MPH;", speed);
- /* Compute speed difference */
- spd_diff = prev_speed - speed;
- printf("debug_zerocase1: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
- printf("debug_zerocase1: speed_diff %.2f\n", spd_diff);
- /* Set conditions for speed difference */
- if(spd_diff > 0 && speed <= 10) {
- /* Safe to cross*/
- printf("Safe to cross \n");
- }
- else if(spd_diff < 0 || speed > 10) {
- printf("DO NOT STEP OFF THE CURB! \n");
- }
- /* Update speeds */
- prev_speed = speed = 0;
- /* Update distances */
- prev_dist = distance = 0;
- /* Get next distance */
- scanf("%f",&prev_dist);
- /* Check if Zero*/
- while(prev_dist == 0){
- scanf("%f", &prev_dist);
- }
- }
- }
- /* Common Case */
- else if(distance != 0) {
- printf("debug_comm case: distance is %.0f and prev_dist is %.0f\n", distance, prev_dist);
- /* Update previous speed */
- prev_speed = speed;
- printf("debug_comm case1: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
- /* Compute Speed */
- speed = ((prev_dist - distance) / 5280) * 3600;
- printf("debug_comm case2: speed is %.2f and prev_speed is %.2f\n", speed, prev_speed);
- }
- }
- printf("\ndebug: end of file\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement