我编写了一个代码,用于检查scanf()何时返回负数,例如,如果按“Ctrl + Z”,它应该退出while循环和printf(“完成!”),但它是不打印“完成!”任何人都可以看看吗?
#include
#include
#include
#define G 9.81
float Height(float speed, float angle, float time);
float Horizontal(float speed, float angle, float time);
void main()
{
float speed;
float angle;
float time = 0.1;
float height = 0;
float horizontal = 0;
int res = 0;
printf("Enter v <0.0 - 100.0 m/s> and a <0-90 degrees>: ");
res = scanf_s("%f %f", &speed, &angle);
while (res != -1)
{
for (time = 0.1; height >= 0; time += 0.1)
{
printf("Time: %.1f .... H = %.2f S = %.2f \n", time, horizontal = Horiz