gpt4 book ai didi

c - 为什么变量 time1 变为零?

转载 作者:行者123 更新时间:2023-11-30 14:24:58 25 4
gpt4 key购买 nike

当我遇到一些问题时,为什么 time1 变量变为零。计算楼层后立即进行。

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
int curfl = 0, destfl, floor;
int time1, high, speed;
high = 3;
speed = 5;
while(1)
{
printf("Currently the elevator is at floor number = %d\n", curfl);
printf("Enter the floor number between 0-25 : ");
scanf("%d", &destfl);
if(destfl > curfl)


{
floor = destfl - curfl;
/*****************************/
time1 = (floor * (high / speed)); //variable become zero here
/*****************************/
printf("Elevator will take %d second to reach %d (st, nd, rd) floor \n", time1, destfl);
while(curfl != destfl)
{
Sleep(1000 * 3 / 5);
curfl++;
printf("You are at floor number %d \n", curfl);
}
printf("Door opening \n");
Sleep(10000);
printf("Door Closed\n");
}
else if(destfl > curfl)
{
floor = curfl - destfl;
time1 = (floor * (3 / 5));
printf("Elevator will take %d second to reach %d (st, nd, rd) floor \n", time1, destfl);
while(curfl != destfl)
{
Sleep(1000 * 3 / 5);
curfl--;
printf("You are at floor number %d \n", curfl);
}
printf("Door opening \n");
Sleep(10000);
printf("Door Closed\n");
}
else{
printf("You are the same floor. Please getout from the elevator \n");
}
}
// printf("Hello world!\n");
return 0;
}

最佳答案

您正在进行整数计算。切换到处理分数的东西。

关于c - 为什么变量 time1 变为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10898949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com