我完全不懂C语言。我在使用带有MinGW编译器的Eclipse。我正在学习scanf和printf函数的使用,目前程序可以正常运行,但是只有在我输入三个整数后才会将语句打印到控制台。
#include <stdio.h>
int main(void){
int length, height, width, volume, dweight;
printf("Enter the box length: ");
scanf("%d", &length);
printf("\nEnter the box width: ");
scanf("%d", &width);
printf("\nEnter the box height");
scanf("%d", &height);
volume = length * width * height;
dweight = (volume + 165) / 166;
printf("Dimensions: l = %d, w = %d, h = %d\n", length, width, height);
printf("Volume: %d\n", volume);
printf("Dimensional Width: %d\n", dweight);
return 0;
}
控制台输出:
8 (user input + "Enter" + key)
10 (user input + "Enter" key)
12 (user input + "Enter" key)
Enter the box length:
Enter the box width:
Enter the box heightDimensions: l = 8, w = 10, h = 12
Volume: 960
Dimensional Width: 6
有什么见解吗?我期望它会打印,然后使用scanf接收用户输入,像这样:
Enter the box length: (waits for user int input; ex. 8 + "Enter")
Enter the box width: ...
fflush(stdout)
。 - Grijesh Chauhan