Jump to content

programme calculation different from correct value

- - - - -

  • Please log in to reply
1 reply to this topic

#1
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
I don't know if I have written the equation correctly or not because when I put in the number into the program and when i calculate it manually using the calculator, the results are different.Here's the code that i wrote. What can I do to make the calculations of the programme correct? And since I get the answer of y output is always negative, how can I make it positive??



#include <stdio.h>

#include <math.h>

#define G  9.801

#define PI 3.142


int main() {

    float t, x, y, angle, Vo, deltat;

    int i;

    FILE* fp;


    printf( "t = " );

    scanf("%f", &t);


    printf( "deltat = " );

    scanf("%f", &deltat);


    printf("initial velocity = ");

    scanf("%f", &Vo);


    printf( "angle = " );

    scanf("%f", &angle);


    fp = fopen( "ParabolicFall.txt", "w" );


    for( i = 0; i <= t; i += deltat ) {


        y = Vo * sin(angle * PI / 180.0) * i - ( G / 2.0 ) * i * i;

        x = Vo * cos(angle * PI / 180.0) * i;


        printf( "t = %d, deltat = %lf, y = %.5f, x = %.5f\n", i, deltat, y, x );

        fprintf( fp, "t= %d, deltat = %lf, y= %f ,x= %f\n", i, deltat, y, x );



    }


    fprintf( stderr, "ParabolicFall.txt was created\n" );

    fclose( fp );

    return 0;

}


Edited by aruwin, 12 December 2011 - 07:15 PM.


#2
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Why do you choose to make a new thread when there are a few members already subscribing to this thread on the same topic. aruwin use code tags. Select your code and click #. It makes the code a lot easier to read. I think you will get a little more help this way.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users