有人能告诉我为什么以下代码在标记行输出0
吗?
看起来一切都正确,但当我尝试在最后获取结果时,每次都会给我0。
#include <stdio.h>
int main() {
// Gather time-lapse variables
int frameRate, totalLengthSecs;
printf("How many frames per second: ");
scanf("%i", &frameRate);
printf("--> %i frames confirmed.", frameRate);
printf("\nDesired length of time-lapse [secs]: ");
scanf("%i", &totalLengthSecs);
printf("--> %i seconds confirmed.", totalLengthSecs);
int totalFrames = frameRate * totalLengthSecs;
printf("\nYou need %i frames.", totalFrames);
// Time-lapse interval calculation
int timeLapseInterval = totalLengthSecs / totalFrames;
printf("\n\n%i", timeLapseInterval); // <-- this prints 0
return 0;
}
stdin
中,以获取“延时拍摄所需的时间长度”? - Dan FegototalLengthSecs / totalFrames
小于1,则会被截断为0,因为所有值都是整数,而不是浮点数。 - Some programmer dude