1

我有一段时间有这个问题。当我尝试运行我的程序时,它会运行,但它会跳过第二个 scanf,即 nudoor,这是我的程序要求门数的部分。

如果有人可以帮忙。这是我的程序运行DOOR SKIP的屏幕截图


int main ()
{
    float length, height, width;
    height = 7.5;   
    
    int nudoor, nuwin, gall, door, win, doorsol, winsol, gallsol, gallsolu;
    gall = 450;
    door = 18;
    win = 9;
    
    printf("Width of Room: ");
    scanf("%.2f",&width);
    printf("Number of doors: ");
    scanf("%d",&nudoor);
    printf("Number of windows: ");
    scanf("%d",&nuwin);
    printf("Length of room: ");
    scanf("%.2f",&length);

    doorsol = nudoor * door;
    winsol = nuwin * win;
    gallsol = doorsol + winsol + length + width + height;
    gallsolu = gallsol/gall;

if (gall >= gallsol)
    printf("Gallons of Paint needed: 0");
else
    printf("Gallons of Paint needed:%d",gallsolu); 

return 0;
}
4

1 回答 1

0

如下图这样的格式字符串

scanf("%.2f",&width);

是不正确的。(与 相对).2的格式字符串没有精度部分。因此,在用于读取浮点数的任何地方都将其删除。scanfprintf

于 2021-10-03T19:20:45.813 回答