刚开始使用C而我在代码中遇到1个错误:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//declare variables
double speed = 1.4, hours, totalYards;
//prompt user to enter amount of hours
printf("Enter the amount of hours: ");
scanf("%lf", &hours);
//calculate amount of yards taken
totalYards = speed * hours;
//display result to user
printf("The total amount of yards is %.2f", &totalYards);
return 0;
}
,错误是
警告:格式&#39;%f&#39;期望类型&#39; double&#39;的参数,但参数2的类型为&#39; double *&#39; [-Wformat] |
在最后一个printf。
答案 0 :(得分:4)
更改
printf("The total amount of yards is %.2f", &totalYards);
到
printf("The total amount of yards is %.2f", totalYards);
您传递的是指针对象(类型为double *
),但f
要求您传递double
类型的值。