Please bare with me as this code I'm posting is not a finished product. It was only to see if my math was working correctly. This is a simple program to calculate the position over time of a projectile using physics kinematic equations. My problems are this:
It only works for the angle 45 degrees. And after I dunno, a few hundred outputs in the text file, it stops incrementing the time by .01 and jumps to something like 4.35001, then 4.36001 and etc. This isn't a big deal as far as accuracy goes... but it's annoying as hell when entering data into excel. Here is my code, any pointers and advice to help me solve the problem would be appreciated! Thanks! (please recall this is not a finished product, my final work looks much better than this):
xpos = cos(angle1)*t
ypos = sin(angle1)*t - g*t*t*0.5 //You're missing a divide by 2 here, if g isn't already halved.
Problem 2:
To fix the precision problems, you just have to specify the output format. Since you're only stepping by 0.01 just fixing precision to 2 decimal places when outputting t should work:
1 2
oFile.precision(2);
oFile << fixed << t
In what way exactly does it "not work" for angles other than 45 deg? Crashing? Wrong output? No output?