问题遇到的现象和发生背景
在dev C++上运行程序
问题相关代码,请勿粘贴截图
#include <stdio.h>
#include <string.h>
#define DENSITY 62.4
int main()
{
float weight, volume;
int size, letters;
char name[40];
printf("Hi! What's your name?\n");
scanf("%s", name);
printf("%s, What's your weight in pounds?\n", name);
scanf("%f", &weight);
size=sizeof(name);
letters=strlen(name);
volume=weight/DENSITY;
printf("Well, %s, your volume is %2.2f cubic feet.\n",name, volume);
printf("Also, your name has %d letters,\n",letters);
printf("and we have %d bytes to store it.\n", size);
return 0;
}
运行结果及报错内容
Hi! What's your name?
Angela Plains
Angela, What's your weight in pounds?
Well, Angela, your volume is 0.00 cubic feet.
Also, your name has 6 letters,
and we have 40 bytes to store it.
我的解答思路和尝试过的方法
直接运行的话,输入名字后回车,直接输出后面所有的内容,没有第二次输入weight的停顿。试了一下单步调试,有第二次输入的停顿,但输入的时候打字不显示,然后查看变量的weight一直=0.
我想要达到的结果
输入名字后回车,第二次可以输入weight敲回车,再显示后面部分。