Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/prolog/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么我会收到这些语法错误消息?_C_Cs50 - Fatal编程技术网

C 为什么我会收到这些语法错误消息?

C 为什么我会收到这些语法错误消息?,c,cs50,C,Cs50,我在CS50,这是我的贪婪 #include <cs50.h> #include <stdio.h> int main (void) { int cents[1000]; int used[1000]; used = 0; printf("How much change is due? (Don't use symbols ex: 0.45)\n"); scanf("%d", cents); if (cents <

我在CS50,这是我的贪婪

#include <cs50.h>
#include <stdio.h>

int main (void) 
{
    int cents[1000];
    int used[1000];
    used = 0;
    printf("How much change is due? (Don't use symbols ex: 0.45)\n");
    scanf("%d", cents);
    if (cents < 0) {
        printf("Please use positve numbers only \n");
        scanf("%d", cents);
    };
    while (cents >= 0.25) {
        cents -= 0.25;
        used+1;
    };
    while (cents >= 0.10) {
    cents -= 0.10;
    used+1;
    };
    while (cents >= 0.05) {
    cents -= 0.05;
    used+1;
    };
    while (cents >= 0.01) {
    cents -= 0.01;
    used+1;
    };
    printf("%d", used);
}
编辑:好的,多亏了@Digital_Reality,我才得以编译,但现在如果我通过1.25,我们使用了1枚硬币,如果通过1000.00,它说我们使用了1000枚硬币,有人知道修复方法吗?

我看到了三个问题

1-->您已将
cents
定义为
1000
元素的数组用作单个整数

2-->您的扫描不正确!(&缺失)

3-->您的
cents
int
数组
,您正试图将if用于
浮点/双精度。

编辑:


阅读这里的一些基础知识:

将声明的美分和用作双变量,而不是数组

      double cents;
      double used;
scanf必须传递一个地址,所以将其设置为变量(&V)

     scanf("%lf",&cents);

您将
cents
定义为数组,但将它们视为单个值。它是哪一个?你真的不需要
美分
使用
就可以成为1000个元素数组,是吗?如果你觉得
int cents[1000]
声明
cents
为一个最大值为1000的整数,请重新阅读您的教科书。好吧,我去掉了1000,但它仍然不起作用@KeithThompson@mrnatbus12:你“摆脱了1000人”;这是否意味着你有
int分[]?它“仍然不起作用”;那到底是什么意思?您的程序是什么样子的?您现在收到了什么错误消息?(还有一个小问题:我猜CS50是一门计算机科学课,但你希望每个人都知道吗?@KeithThompson它看起来像整数美分;好的,我去掉了100并添加了符号,但现在最后一行不起作用了。错误:贪婪。c:31:6:警告:格式“%d”要求参数类型为“int”,但参数2的类型为“int*”[-Wformat=]printf(“我们使用了%d个硬币”,&used);                                                         ## 编辑###:我修正了它,但在printfs中你不应该使用&。是的,我只是在@digital#u RealiltyOkay修改了它。我确实编译了,但不一定工作请检查编辑
      double cents;
      double used;
     scanf("%lf",&cents);