Home > Net >  Why is my program skipping the 2nd scanf line?
Why is my program skipping the 2nd scanf line?

Time:10-04

I had this problem for a while. when I try to run my program, It will run but it will skip the 2nd scanf which is the nudoor, the part where my program ask for number of doors.

If anyone could help. Here's the screenshot of my program running 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;
}

CodePudding user response:

Such a format string as shown below

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

is incorrect. There is no precision part .2 of a format string for scanf (opposite to printf). So remove it everywhere where it is used to read float numbers.

  • Related