什么意思分配给'浮动'来自不兼容的类型'浮动?

时间:2018-04-02 12:41:11

标签: c function call

这是一条错误消息:

  

分配给'浮动'来自不兼容的类型&#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);
}

1 个答案:

答案 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

相关问题