gpt4 book ai didi

c++ - float 减法问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:34:21 24 4
gpt4 key购买 nike

<分区>

这个程序必须计算最小数量的硬币,但它有一些错误,因为结果很奇怪。这可能是明显的错误,但我找不到。

int main(int argc,char* argv[]){
float x;
printf("How much cash in float number:");
scanf("%f", &x);

int quaters;
while(x>=0.25){
x-=0.25;
quaters++;
}
printf("%f\n",x);

int fives;
while (x>=0.05){
x-=0.05;
fives++;
}
printf("%f\n",x);

int one;
while (x>=0.01){
x-=0.01;
one++;
}
printf("%f\n",x);
printf("quaters %d\t fives %d\t ones %d\n", quaters, fives, one);
return 0;
}

输出是这样的

    How much cash in float number:0.41
0.160000
0.010000
0.010000
quaters 1 fives 3 ones 32764

怎么了?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com