Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to fix my code in C language programming

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 477
    Answer it

    Hello i am doing an exercise that states: 

    A 3000 lb  vehicle travelling on a road at 100 ft/sec requires a force equal to its mass times its acceleration to stop ( F = ma).

    The acceleration is given by

    a=  (v_o^2-v_i^2)/2d 

    Where  vi = 100 ft/sec

     vo = 0 ft/sec.

     Write a program that will calculate the retarding force needed to stop the car at distances of 10, 20, 30, 40, 50, …, 1000 ft. Display the distance value and the corresponding retarding force in tabular form. The units of force are Newtons (N). Your solution must include a user-defined function that returns the force and takes as input initial and final velocity and distance.

    double force(double velocityInitial, double velocityFinal, double distance, double mass);

     

    I have tried the following: 

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

        double force(double velocityInitial, double velocityFinal, double distance, double mass);

    int main()
    {

        double forceFormula;
        int distance, mass, acceleration;

        forceFormula = mass * acceleration;

        printf("\nDistance:\t\tForce in Newtons:\n"
            "------------------------------------------\n");
        printf("%d\t\t\t%.2lf\n", distance, forceFormula);
        printf("------------------------------------------\n");

        return 0;
    }


        double force(double velocityInitial, double velocityFinal, double distance, double mass)
        {
            velocityInitial = 100;
            velocityFinal = 0;
            mass = 3000;

            double acceleration, forceFormula;

                for( distance = 10; distance <= 1000; distance += 10)
                {

                   acceleration = ((velocityFinal * velocityFinal) - (velocityInitial * velocityInitial))/ 2 * distance;

                   forceFormula = mass * acceleration;
                }

        return forceFormula;

    }
     

    I am not sure where it is that I am making a mistake, if its in the variables, the function definition... I really appreciate the help, thanks.

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: