Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.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 - Fatal编程技术网

C编程不断崩溃

C编程不断崩溃,c,C,我似乎不知道出了什么问题;我得到了一个干净的编译,但在输入第一个数字后,它崩溃了 for (day = 1; day < 15; day++) { do { printf("What is the temperature high for day #%d? ", day++); scanf("%d", temperature[day]); sum += temperature[day]

我似乎不知道出了什么问题;我得到了一个干净的编译,但在输入第一个数字后,它崩溃了

    for (day = 1; day < 15; day++)
{
    do
        {
            printf("What is the temperature high for day #%d? ", day++);
            scanf("%d", temperature[day]);

            sum += temperature[day];

                if (temperature[day]<0 || temperature[day]>100)
                {
                    printf("\nOut of range, please enter a value from 0 to 100\n\n");
                }


            if (temperature[day] < 60)
                {
                    cold++;
                }

            else if (temperature[day] >= 60)
                {
                    warm++;
                }

            else if (temperature[day] > 69 || temperature[day] < 80)
                {
                    printf("Wow! It's in the 70's today!");
                    warm++;
                }
for(天=1;天<15;天++)
{
做
{
printf(“第#%d天的最高温度是多少?”,第++);
scanf(“%d”,温度[天]);
总和+=温度[天];
if(温度[天]100)
{
printf(“\n超出范围,请输入从0到100的值\n\n”);
}
如果(温度[天]<60)
{
冷++;
}
否则,如果(温度[天]>=60)
{
warm++;
}
否则如果(温度[日]>69 | |温度[日]<80)
{
printf(“哇!今天是70年代!”;
warm++;
}

任何帮助,即使是提示,我们都将不胜感激!!

您尚未显示
温度的定义,但根据您的使用情况

scanf("%d", temperature[day]);
几乎可以肯定

scanf("%d", &temperature[day]);

当您想从用户输入时,必须提供如下所示的
&
登录scanf()函数

scanf("%d", &temperature[day]);

scanf()函数中缺少
&
符号。添加它,您的问题将得到解决。

int和int*不匹配

scanf("%d", &temperature[day]);
而不是

scanf("%d", temperature[day]);
此处不要增加
day
,它已经作为
for
循环的一部分增加,否则循环体其余部分对
day
的解释是错误的


它可能是
scanf(“%d”,&temperature[day]);
,因为
scanf()
需要变量的地址。

哪里定义了“temperature”数组?抱歉!我不能在这段代码中显示,但在这段代码上面我定义了温度sidenote
day
:它在两个地方递增。您说“我得到了一个干净的编译”但是您使用的编译器标志是什么?您使用的是GCC吗?您使用的是
-Wall
-Wextra
标志吗?它们对于查找这样的错误非常重要。3答案,并且没有一个解释为什么(可能)需要
&
。。。
    for (day = 1; day < 15; day++)
{
    do
        {
            printf("What is the temperature high for day #%d? ", day++);
    scanf("%d", temperature[day]);