Question: A cyclist coasting on a level road slows from a speed of 10 mi/hr to 2.5 mi/hr in one minute. Write a computer program that calculates the cyclist’s constant rate of acceleration and determines how long the cyclist will take to come to rest, given an initial speed of 10 mi/hr. ( Hint: Use the equation
a = vf - vi / time
where a is acceleration, t is time interval, v i is initial velocity, and v f is finalvelocity.) Write and call a function that displays instructions to the program user and a function that computes a, given t, vf , and vi .
The teacher told me that you have written the wrong code.
Here is my code: Tell me what is the wrong ?
Code:
#include <stdio.h>
void Calculate ( float initial_velocity, float final_velocity, float time );
int main()
{
float initial_velocity, final_velocity, time;
printf("Enter your cycling details to calculate the acceleration:\n\n");
printf("Initial Velocity: ");
scanf("%f",&initial_velocity);
printf("Final Velocity: ");
scanf("%f",&final_velocity);
printf("Time: ");
scanf("%f",&time);
Calculate (initial_velocity, final_velocity, time );
return 0;
}
void Calculate ( float initial_velocity, float final_velocity, float time )
{
float acceleration;
acceleration = ( final_velocity - initial_velocity ) / time;
printf("\nAcceleration: %.2f",acceleration);
}