-5

嗨,我已经编写了这段代码,但输出如下:

你旅行了多少英里?:(你显示的次数)
你消耗了多少加仑汽油?:

然后它只是跳过扫描并移动到下一个位置,

#include <stdio.h>
#include <string.h>
#include <float.h>

int main ()
{

    float mile;
    float gallon;

    printf("How many Miles have u traveled?: ");
    scanf("%.1f",&mile);
    printf("How many gallons of gasoline have u consumed?: ");
    scanf("%.1f",&gallon);

} 
4

1 回答 1

2

您不应该格式化输入。所以只需%f用作的第一个参数scanf

int main ()
{

    float mile;
    float gallon;

    printf("How many Miles have u traveled?: ");
    scanf("%f",&mile);
    printf("How many gallons of gasoline have u consumed?: ");
    scanf("%f",&gallon);

} 
于 2013-04-15T18:34:37.140 回答