Loops while循环条件
下面是代码的结果。我试图打印结果如下:0,5,10。然后,所述秒的结果将打印速度和加速度 任何帮助都将不胜感激。我卡住了Loops while循环条件,loops,for-loop,while-loop,conditional-statements,Loops,For Loop,While Loop,Conditional Statements,下面是代码的结果。我试图打印结果如下:0,5,10。然后,所述秒的结果将打印速度和加速度 任何帮助都将不胜感激。我卡住了 谢谢。这不是你的问题,但是你真的需要这类东西吗?你确定你的语言是对的,因为我不是。请研究C++与C语言的区别,并根据不是C代码编写你的标签。 int k=时间;然后立即用k=0初始化循环。另外,在循环中根本不使用k,这应该是一个危险信号。用C编译器编译这些代码有多好?这是C++(好,它使用C的库,但它是C++)我运行代码,它没有给我任何错误。当我输入一个时间值即10时,它显示
谢谢。这不是你的问题,但是你真的需要这类东西吗?你确定你的语言是对的,因为我不是。请研究C++与C语言的区别,并根据不是C代码编写你的标签。<代码> int k=时间;
然后立即用k=0初始化循环代码>。另外,在循环中根本不使用k
,这应该是一个危险信号。用C编译器编译这些代码有多好?这是C++(好,它使用C的库,但它是C++)我运行代码,它没有给我任何错误。当我输入一个时间值即10时,它显示的就是这个值。
double velocity;
double time;
double acceleration;
char buff[10];
int y;
//Asking user for a time value
printf("Enter a time value in seconds: ");
//QC to make sure program is running correctly
fgets(buff, 10, stdin);
char x = buff[0];
y = isdigit(x);
if (y == 0)
{
printf("Error. You have entered a non numerical number, please enter a numerical number\n");
}
else
{
sscanf(buff, " %lf", &time);
//Displaying Velocity and Acceleration if time is between 0 and 120 seconds
if (time >= 0 && time <= 120)
{
int k = time;
for (k = 0; k <= 120 && k <= time; k = k + 5)
{
//Equation to find velocity and acceleration
velocity = 0.000001 * pow(time, 3) - 0.00488 * pow(time, 2) + 0.75795 * time + 181.3566;
acceleration = 3 - 0.000062 * pow(velocity, 2);
printf("%.lf %.1lf %.3lf\n", time++, velocity++, acceleration++);
} //for while loop
} //if statement
//Displaying an error message if time is inputted lower than 0 and greater than 120 seconds
else
{
printf("Error. You have entered a value that is not between 0 and 120 seconds.\n");
}
}
return 0;
10 188.4 0.798
11 189.1 0.783
12 189.8 0.768