Thread: Write a computer program that calculates the cyclist’s constant rate of acceleration

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    7

    Exclamation Write a computer program that calculates the cyclist’s constant rate of acceleration

    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);
        
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,662
    > Write a computer program that calculates the cyclist’s constant rate of acceleration
    This you've done.

    > and determines how long the cyclist will take to come to rest,
    This you haven't.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Quote Originally Posted by Salem View Post
    > Write a computer program that calculates the cyclist’s constant rate of acceleration
    This you've done.

    > and determines how long the cyclist will take to come to rest,
    This you haven't.
    Hi, tell me that how to do that. Please give me some point for that determines.

  4. #4
    Registered User
    Join Date
    Apr 2015
    Posts
    7
    Quote Originally Posted by Salem View Post
    > Write a computer program that calculates the cyclist’s constant rate of acceleration
    This you've done.

    > and determines how long the cyclist will take to come to rest,
    This you haven't.
    I think I should have to find out time to stop as given this code.
    Code:
      time = (final_velocity - initial_velocity) / acceleration;

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    582
    I keep looking at that equation and trying to figure out how to use it to travel back in time.

    Anyway, yes, that's right. Just plug in the numbers to solve for time. I think it means the total time from 10 mph to stopping.

    It'd also be nice to prompt the user for the units to use for time, so you can format the output into minutes and seconds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2012, 01:17 AM
  2. Replies: 3
    Last Post: 02-23-2012, 11:35 PM
  3. Frame Rate Not Constant
    By OhPoo in forum Windows Programming
    Replies: 14
    Last Post: 01-16-2012, 08:04 PM
  4. write a program to computer>>
    By adilmor in forum C Programming
    Replies: 10
    Last Post: 03-27-2009, 10:42 AM
  5. Program that calculates the value of PI
    By noodles in forum C Programming
    Replies: 7
    Last Post: 09-06-2006, 05:20 AM

Tags for this Thread