我试图找到在 C 中以恒定速度移动输入距离所花费的时间。我有功能但输出打印为 0 的代码?知道出了什么问题吗?
#include <stdio.h>
#include <stdlib.h>
int main() {
int distance, speed = 80;
float time;
// This is how to read an int value
printf("Please enter a distance in kilometers to be covered at 80KPH. \n");
scanf("%d", & distance);
printf("You typed: %d\n", distance);
printf("\n");
time = distance / speed;
printf("It will take you %.2f to cover ", time);
}