Like Tree2Likes
  • 1 Post By rags_to_riches
  • 1 Post By iMalc

Paraoblic Path

This is a discussion on Paraoblic Path within the C++ Programming forums, part of the General Programming Boards category; I have a task that I have to submit immediately.OK,here are the instructions. Creating a programme for parabolic path/parabolic motion. ...

  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
    Name:  results.JPG
Views: 167
Size:  70.9 KB

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

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    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.
    Salem likes this.
    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, 07:14 AM
  3. path of app
    By joeyzt in forum C++ Programming
    Replies: 5
    Last Post: 01-15-2006, 11:23 AM
  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, 06:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21