c - 对于 pset1 中的现金问题,如何使输出正常工作?
问题描述
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
float a;
int coins = 0;
do
{
a = get_float("Value of change in dollars: ");
}
while (a < 0);
{
int change = round(a * 100);
while (change / 25 >= 1)
{
coins++;
change = change % 25;
}
while (change / 10 >= 1)
{
coins++;
change = change % 10;
}
while (change / 5 >= 1)
{
coins++;
change = change % 5;
}
while (change / 2 >= 1)
{
coins++;
change = change % 2;
}
while (change / 1 >= 1)
{
coins++;
change = change % 1;
}
}
printf("%i\n", coins);
}
这些是我的输出:
:) cash.c exists
:) cash.c compiles
:) input of 0.41 yields output of 4
:) input of 0.01 yields output of 1
:) input of 0.15 yields output of 2
:( input of 1.6 yields output of 7
expected "7\n", not "2\n"
:( input of 23 yields output of 92
expected "92\n", not "1\n"
:( input of 4.2 yields output of 18
expected "18\n", not "2\n"
:) rejects a negative input like -1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
解决方案
推荐阅读
- sql - SQL Table 数十亿条目 - 寻找性能建议
- graphql - 错误:无效的 AST 节点:{"input":"** } on graphql 突变(放大客户端)
- javascript - 无法使用 Lightning 组件中的 FileReader 对象读取和上传文件
- node.js - JHipster 安装失败
- webpack - webpack 带有样式加载器的错误
- java - IntelliJ 中文件更改的代码生成
- c - 将结构传递给C中的函数时损坏
- reactjs - 无法将 SVG 图像导入我的打字稿应用程序
- gradle - Flutter App 卡在“正在运行 Gradle 任务 'assembleDebug'...”
- r - 运行 rmh 时尝试保存中间状态会产生错误