Hey! can you tell me what's wrong with my code?
it is suposed to calculate and graph time vs. distance. The problem I have is graphing, if I put too small values for Vi, which is the initial velocity, it just graphs one or two points, because t is too small. I alredy tried to adjust t with 'if(t<10) t=t*10; if (t>100) t=t/10;', But it seems not to solve my problem.
Other truble I have is that, as the graph is parabola, core values ​​are very close together, and when plotted, these values ​​are in the same line on the screen.
Here is my code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x, y, hmax, t, amax, vi, v, a, b, g, ang; /*x= x coordinate, y= y coordinate, hmax= maximum height, amax= total distance on x axis, vi= initial velocity, ang= shot angle, a, b and c are just to make my life easier*/
g=9.81;
clrscr();
printf("Soy un programa que calcula un tiro parab¢lico y adem*s lo grafica\n");
printf("Dame el *ngulo de lanzamiento: ");
scanf("%f",&ang); //asking for shot angle
printf("Dame la velocidad inicial: ");
scanf("%f",&vi); //asking for initial velocity
hmax=(vi*sin(ang)*vi*sin(ang))/(2*g);
t=(2*vi*sin(ang))/g;
amax=vi*cos(ang)*t;
printf("El tiempo total es %f\nLa altura m*xima es %f\nEl alcance m*ximo es %f",t,hmax,amax); //printing out values
getch();
if(t>=100)
t=t/10;
if(t<=10)
t=t*10;
clrscr();
for(x=0;x<=t;x++) //here is the problem
{
y=vi*sin(ang)*x-(g*x*x)/2;
gotoxy(x,y);
printf("ø");
}
getch();
}