这是一条错误消息:
分配给'浮动'来自不兼容的类型&#float; const(const string,...)' (aka' float(char * const,...)')
代码:
int main(void) {
float n = -1;
int z = 0;
int counter = 0;
do {
printf("Input positive money amount such as $5.13 as '5.13' \n");
n = get_float;
} while (n < 0);
n = n * 100;
n = round(n);
z = n;
while (z >= 25) {
z = z - 25;
counter++;
}
while (z >= 10) {
z = z - 10;
counter++;
}
while (z >= 5) {
z = z - 5;
counter++;
}
while (z >= 1) {
z = z - 1;
counter++;
}
printf("number of minimum coins needed %d", counter);
}
答案 0 :(得分:1)
在此表达式声明中
n = get_float;
变量n
的类型为float
,而表达式get_float
为函数指针float ( * )(const string, ...)
。
你应该写
n = get_float( "Input positive money amount such as $5.13 as '5.13: ' );
那就是你需要调用函数而不是将函数的指针赋给变量n
。