该程序模拟以固定垂直和水平速度以一定角度发射的物体的抛物线轨迹。它以终端控制台中显示的坐标输出数据。
但是,程序只输出到第二行的数据并终止,所以代码中一定有错误。我无法识别错误,所以我请求帮助!
#include <stdio.h>
#include <stdlib.h>
int main(void) {
float lvelox;
float lveloy;
float xcord;
float ycord;
int stepcount;
int step = 0;
/* Initializing velocity */
{
printf("Enter the initial h velocity of the ball:\n");
scanf("%f", &lvelox);
printf("Enter the initial v velocity of the ball:\n");
scanf("%f", &lveloy);
}
/* Obtain number of steps */
{
printf("Enter the number of steps wanted:\n");
scanf("%d", &stepcount);
}
/* formula for calculating initial position */
if ( step == 0 )
{
xcord = 0;
ycord = 0;
step = step + 1;
printf("\n");
printf("xcord, ycord, step\n");
printf("\n");
printf("%f, ", xcord);
printf("%f, ", ycord);
printf("%d\n", step);
}
/* Loop method */
if ( step < stepcount )
{
lveloy = lveloy - 9.81;
xcord = xcord + lvelox;
ycord = ycord + lveloy;
step = step + 1;
printf("%f, ", xcord);
printf("%f, ", ycord);
printf("%d\n", step);
if ( ycord < 0 )
{
lveloy = (lveloy * -1);
lveloy = lveloy - 9.81;
xcord = xcord + lvelox;
ycord = ycord + lveloy;
step = step + 1;
printf("%f, ", xcord);
printf("%f, ", ycord);
printf("%d\n", step);
}
}
if (step >= stepcount)
{
return 0;
}
}