Jump to content

txt out put and programme out are different

- - - - -

  • Please log in to reply
11 replies to this topic

#1
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
Why does the txt file created by the programme presents different data than the output presented by the programme?

Here is the programme output
Attached File  results.JPG   30.99K   19 downloads

And this is the txt file created
Attached File  data.JPG   44.69K   14 downloads

#2
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
Where's the code?

#3
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts

lespauled said:

Where's the code?

#include <stdio.h>
#include <math.h>
#include <stdio.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) * i - ( G / 2.0 ) * i * i * -1;
x = Vo * cos(angle * PI / 180) * i;

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

}

fprintf( stderr, "ParabolicFall.txt was created\n" );
fclose( fp );
return 0;
}

#4
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
The print formats are different. Change the fprintf to use the same format as the printf and it works fine.

#5
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts

lespauled said:

The print formats are different. Change the fprintf to use the same format as the printf and it works fine.

Thanks!It works fine now :)

#6
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
No need to PM me with questions. The problem with the calculations may have to do with the order of precedence (Order of operations - Wikipedia, the free encyclopedia).

#7
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts

lespauled said:

No need to PM me with questions. The problem with the calculations may have to do with the order of precedence (Order of operations - Wikipedia, the free encyclopedia).

And now,how do I replace t with delta t as the output in the txt file?.Because I have to plot a graph using the value of delta t instead of t.

#8
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
aruwin use code tags. Next time select your code and click #. :)
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#9
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
I'm not sure what you're asking. You are using deltat as the increment value for "i" in your for loop. That increments i, as long as it is less than or equal to "t'.

Where exactly do you want to place it? Inside the loop?

#10
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts

lespauled said:

I'm not sure what you're asking. You are using deltat as the increment value for "i" in your for loop. That increments i, as long as it is less than or equal to "t'.

Where exactly do you want to place it? Inside the loop?

No,i mean right now,the graph uses t to plot the graph but instead of value t,I want the value of felta t which is gonna be always the same because I want draw a parabolic path.

#11
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
then just add it to the print and printf statements.

#12
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts

lespauled said:

I'm not sure what you're asking. You are using deltat as the increment value for "i" in your for loop. That increments i, as long as it is less than or equal to "t'.

Where exactly do you want to place it? Inside the loop?

Hey,and just one more thing really.I didnt realize this before.To make the parabolic graph,I need to use the value of delta t instead of t which means the time is gonna be the same always cuz delta t does not change.So, can you write out the code for the value of delta t to appear in the output as well?Right now the outputs are only t ,y displacement and x displacement.

---------- Post added at 04:15 PM ---------- Previous post was at 03:38 PM ----------

lespauled said:

then just add it to the print and printf statements.

Thanks.Got it done already. :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users