C学生作业,'%f'需要'float*'类型的参数,但参数2的类型为'double*'

Dav*_*vey 8 c double reference

我正在完成任务,我收到了这个警告:

C4_4_44.c:173:2: warning: format ‘%f’ expects argument of type ‘float *’, 
but argument 2 has type ‘double *’ [-Wformat]
Run Code Online (Sandbox Code Playgroud)

变量在main中声明为:

double carpetCost;
Run Code Online (Sandbox Code Playgroud)

我把这个函数称为:

getData(&length, &width, &discount, &carpetCost);
Run Code Online (Sandbox Code Playgroud)

这是功能:

void getData(int *length, int *width, int *discount, double *carpetCost)

{

    // get length and width of room, discount % and carpetCost as input

    printf("Length of room (feet)? ");

    scanf("%d", length);

    printf("Width of room (feet)? ");

    scanf("%d", width);

    printf("Customer discount (percent)? ");

    scanf("%d", discount);

    printf("Cost per square foot (xxx.xx)? ");

    scanf("%f", carpetCost);

    return;

} // end getData
Run Code Online (Sandbox Code Playgroud)

这让我抓狂,因为这本书说你不使用&in

scanf("%f", carpetCost); 
Run Code Online (Sandbox Code Playgroud)

从您传递它的函数访问它时,请参考.

我在这里做错了什么想法?

oua*_*uah 8

更改

scanf("%f", carpetCost);
Run Code Online (Sandbox Code Playgroud)

scanf("%lf", carpetCost);
Run Code Online (Sandbox Code Playgroud)

%f转换规范用于float *说法,你需要%lfdouble *参数.