【发布时间】:2021-06-07 06:38:06
【问题描述】:
我完成了 cash.c 的代码,但我无法编译它。在 //最少数量的硬币以进行一定数量的更改部分,我的每个 都有一个“预期表达式”错误。我尝试更改它几次,甚至查看我做错了什么,但我找不到任何东西。有人可以帮帮我吗?另外,我很想听听有关我的代码的任何建议或反馈!代码在下面。
谢谢! 阿莱娜
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
// prompt user for non-negative input & convert dollars to cents
float change;
int cents;
do
{
change = get_float("How much change? ");
cents = round(change * 100);
}
while (change < 0);
//least amount of coins to make certain amount of change
int coins;
coins = 0;
while (cents >= 0.25)
{
coins++;
cents = cents - 25;
}
while (cents >= .1 && < 0.25)
{
coins++;
cents = cents - 10;
}
while (cents >= .05 && < .1)
{
coins++;
cents = cents - 5;
}
while (cents >= 0.01 && < .05)
{
coins++;
cents = cents - 1;
}
printf("%i\n", coins);
}
我也想知道我在cs50上遇到困难是否正常?我理解讲座和短片中的所有内容,但问题集似乎花了我很长时间。我花了大约 3 周的时间才完成 mario.c,如果没有谷歌搜索,我就无法完成。这让我怀疑我是否应该在没有任何经验的情况下听这门课程。我真的很喜欢这门课程,但你认为我应该把它降低一个档次,从对初学者更友好的东西开始吗?
【问题讨论】:
-
我个人不会从 C 开始编程 - 像 Python 这样的高级语言更容易掌握。
标签: c while-loop syntax-error cs50 logical-and