【问题标题】:What does mean assigning to 'float' from incompatible type 'float?从不兼容的类型'float'分配给'float'是什么意思?
【发布时间】:2018-09-11 16:24:43
【问题描述】:

这是一条错误消息:

从不兼容的类型'float(const string,...)'(又名'float(char *const,...)')分配给'float'

代码:

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);
}

【问题讨论】:

  • 你能显示代码吗?
  • @sabatilius 将代码放在问题中而不是评论中。

标签: c function call


【解决方案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

【讨论】:

    猜你喜欢
    • 2012-11-26
    • 2021-11-24
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2017-07-11
    相关资源
    最近更新 更多