誰かが次のコードがマークされた行に0
を出力している理由を教えてもらえますか?なぜこの整数除算は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;
}
"希望の長さの経過時間"には何を入力していますか? –
'totalLengthSecs/totalFrames'が1より小さい場合は、すべての値が浮動小数点数ではなく整数であるため、切り捨てられます。 –