Thread: Paraoblic Path

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    Paraoblic Path

    I have a task that I have to submit immediately.OK,here are the instructions.
    Creating a programme for parabolic path/parabolic motion.
    -The object is shot from the ground and there must be 4 input datas : the duration of time (t),the angle,initial velocity and the time interval of the displacement(delta t).
    -The output should be the displacement in both the x and y direction.
    - projection time is set to 0
    - the position after t seconds is calculated by delta t second intervals(t and delta t is also input after the program runs).
    - the result is output to the file, use Excel to make graph with it

    I am having problems with writing the equations correctly and also with t and delta t

    Here's what I have done so far.Someone correct me please.

    Code:
    #include <stdio.h>
    #include <math.h>
    #define g 9.8
    int main()
    {
    double t, x, y, angle, Vo, deltat;
    char buf[256];
    int i;
    FILE* fp;
    printf( "t = " );
    fgets( buf, 256, stdin );
    sscanf( buf, "%lf\n", &t );
    printf( "deltat = " );
    fgets( buf, 256, stdin );
    sscanf( buf, "%lf\n", &deltat );
    printf("initial velocity = ");
    sscanf( buf, "%lf\n", &Vo );
    fgets( buf, 256, stdin );
    printf( "angle = " );
    sscanf( buf, "%lf\n", &angle );
    fgets( buf, 256, stdin );
    
    fp = fopen( "z:\\FreeFall.txt", "w" );
    for( i = 0; i < t; 'i+=deltat' ) {
    y = Vo*sin(angle)*deltat - ( g / 2.0 ) *deltat * deltat;
    x = Vo*cos(angle)*deltat;
    
    
    printf( "i= %f, y= %f ,x= %f\n", t, y, x );
    fprintf( fp, "i=, %f, y=, %f ,x= %f\n", t, y, x );
    }
    fprintf( stderr, "File z:\\FreeFall.txt was created\n" );
    fclose( fp );
    return 0;
    }
    Here's the results.It came out endless and with weird results
    Paraoblic Path-results-jpg

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    for( i = 0; i < t; 'i+=deltat' ) {
    Why would you have quotes around the increment statement in this loop?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Also fix your indentation. I'm not wasting my time matching up your for loop start and end brackets when you're supposed to make it clear by formatting the code properly.
    I'm not picking on you, I try to tell everybody this, even if their code only has a few braces total, in it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get path?
    By arul in forum C Programming
    Replies: 6
    Last Post: 10-11-2008, 02:44 PM
  2. path
    By yes in forum C++ Programming
    Replies: 12
    Last Post: 01-29-2006, 08:14 AM
  3. path of app
    By joeyzt in forum C++ Programming
    Replies: 5
    Last Post: 01-15-2006, 12:23 PM
  4. what is the best path to take?
    By oceanrats in forum C++ Programming
    Replies: 3
    Last Post: 05-14-2005, 10:59 PM
  5. How to set the path WIN XP
    By rippascal in forum C++ Programming
    Replies: 1
    Last Post: 03-26-2002, 07:45 PM