我不知道´;我不明白我的代码是如何为cs50现金较少舒适的pset1工作的,有人能帮我吗? #包括 #包括 #包括 //向用户请求他们的更改,然后*乘以100将其四舍五入并返回一个整数值 浮动变化(无效); //获取change()并跟踪硬币的数量,然后返回该值 国际货币计数(无效); 内部主(空) { printf(“%i\n”,count_coins()); } 硬币计数(无效) { 整数总计=四舍五入(更改()*100); 国际季度=25; int-dime=10; int镍=5; 整数=1; //剩余部分将在用户签名和硬币之间存储% //总计数将存储每种类型硬币的硬币数量 //temp将临时存储硬币装入零钱的次数 整数余数; 内部温度; 整数总计数=0; 如果(总分>=季度) { 剩余部分=总分占季度的百分比; 温度=(总分-剩余分); 总计数=总计数+(临时/季度); 总分=剩余分; } 如果(总分>=一角) { 余数=总美分%一角; 温度=(总分-剩余分); 总计数=总计数+(温度/硬币); 总分=剩余分; } 如果(总分>=镍) { 剩余=总镍百分比; 温度=(总分-剩余分); 总计数=总计数+(温度/镍); 总分=剩余分; } 如果(总分>=便士) { 余数=总美分%便士; 温度=(总分-剩余分); 总计数=总计数+(临时/便士); 总分=剩余分; } 返回总计数; } 浮动更改(无效) { 浮动用户不改变; 做 { 用户更改=获取浮动(“更改:\n”); } 而(用户变化

我不知道´;我不明白我的代码是如何为cs50现金较少舒适的pset1工作的,有人能帮我吗? #包括 #包括 #包括 //向用户请求他们的更改,然后*乘以100将其四舍五入并返回一个整数值 浮动变化(无效); //获取change()并跟踪硬币的数量,然后返回该值 国际货币计数(无效); 内部主(空) { printf(“%i\n”,count_coins()); } 硬币计数(无效) { 整数总计=四舍五入(更改()*100); 国际季度=25; int-dime=10; int镍=5; 整数=1; //剩余部分将在用户签名和硬币之间存储% //总计数将存储每种类型硬币的硬币数量 //temp将临时存储硬币装入零钱的次数 整数余数; 内部温度; 整数总计数=0; 如果(总分>=季度) { 剩余部分=总分占季度的百分比; 温度=(总分-剩余分); 总计数=总计数+(临时/季度); 总分=剩余分; } 如果(总分>=一角) { 余数=总美分%一角; 温度=(总分-剩余分); 总计数=总计数+(温度/硬币); 总分=剩余分; } 如果(总分>=镍) { 剩余=总镍百分比; 温度=(总分-剩余分); 总计数=总计数+(温度/镍); 总分=剩余分; } 如果(总分>=便士) { 余数=总美分%便士; 温度=(总分-剩余分); 总计数=总计数+(临时/便士); 总分=剩余分; } 返回总计数; } 浮动更改(无效) { 浮动用户不改变; 做 { 用户更改=获取浮动(“更改:\n”); } 而(用户变化,c,cs50,greedy,coin-change,C,Cs50,Greedy,Coin Change,您好,这是我的cs50现金不太舒服问题集的代码,但是我不知道怎么做 级联if语句在函数int count_coins(void)中起作用,我的意思是total_cents变量如何存储余数的值而忽略我设置为的初始定义 在if cascade int total_cents=round(change()*100) 另外,变量int total_count=total_count+(临时/硬币类型)如何跟踪所有 这些硬币是怎么加起来的 对不起,如果我没有很好地解释我自己,但我真的不知道我在做什么。你写

您好,这是我的cs50现金不太舒服问题集的代码,但是我不知道怎么做
级联if语句在函数int count_coins(void)中起作用,我的意思是total_cents变量如何存储余数的值而忽略我设置为的初始定义 在if cascade int total_cents=round(change()*100)

另外,变量int total_count=total_count+(临时/硬币类型)如何跟踪所有 这些硬币是怎么加起来的


对不起,如果我没有很好地解释我自己,但我真的不知道我在做什么。

你写了那段代码,但不知道它是如何工作的?那你是怎么写的?您应该开始使用调试器逐步完成代码。对于这么小的程序来说,这不是什么大问题。在逐步执行代码时,必须注意变量。检查它们的值。“我的意思是total_cents变量如何存储余数的值,而忽略初始定义我将其设置为if级联之前的值”它们被称为变量,因为随着时间的推移改变值是正常的。这并不是忽视你的初始化。在计算的每一步中都会对该值进行简单的调整。感谢您提供的答案,现在我已经进行了更多的练习和研究,我对它有了更好的理解。有关解释,请参阅我的。(或者可能不是那个问题,我错贴了标签?…)
# include <stdio.h>
# include <cs50.h>
# include <math.h>

   // Asks user for their change then * by 100 rounds that up and returns an integer value
float change(void);
    // takes change() and keeps track of the number of coins andthen returns that
int count_coins(void);

int main(void)
{
    printf("%i\n", count_coins());

}


int count_coins(void)
{
    int total_cents = round (change() * 100);

    int quarter = 25;

    int dime = 10;

    int nickel = 5;

    int penny = 1;

    // remainder will store the % between the userschange and the coins
    //total_count will store the amunt of coins for ach type of coin
    // temp will temporarilly store the number of times a typeof coin fits into the change
    int remainder;
    int temp;
    int total_count = 0;

    if (total_cents >= quarter)
    {

        remainder = total_cents % quarter;

        temp = (total_cents - remainder);

        total_count = total_count + (temp / quarter);

        total_cents = remainder;
    }

    if (total_cents >= dime)
    {

        remainder = total_cents % dime;

        temp = (total_cents - remainder);

        total_count = total_count + (temp / dime);

        total_cents = remainder;
    }

    if (total_cents >= nickel)
    {

        remainder = total_cents % nickel;

        temp = (total_cents - remainder);

        total_count = total_count + (temp / nickel);

        total_cents = remainder;
    }

    if (total_cents >= penny)
    {

        remainder = total_cents % penny;

        temp = (total_cents - remainder);

        total_count = total_count + (temp / penny);

        total_cents = remainder;
    } 

    return total_count;
    }

    float change(void)
    {

    float users_change;
    do

    {
       users_change = get_float("Change:\n");
    }

    while (users_change < 0);

    return users_change;

    }