简体   繁体   English

C编程不断崩溃

[英]C Programming Keeps Crashing

I can't seem to figure out what's wrong; 我似乎无法弄清楚出了什么问题。 I get a clean compile but after inputting the first number, it crashes. 我得到了一个干净的编译器,但是输入第一个数字后,它崩溃了。

    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++;
                }

Any help, even a hint, would be greatly appreciated!! 任何帮助,甚至暗示,将不胜感激!

You haven't shown the definition of temerature , but based on your usage, 您还没有显示的定义temerature ,但根据您的使用情况,

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

should almost certainly be 几乎应该是

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

When you want to input from the user , you must provide & sign in scanf() function like below, 当您要从用户输入内容时,必须提供&登录scanf()函数,如下所示,

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

You are missing & sign in your scanf() function. 您丢失了&登录到scanf()函数。 Add it and your problem will be solved. 添加它,您的问题将得到解决。

mismatch between int and int *. int和int *不匹配。

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

instead of 代替

scanf("%d", temperature[day]);
  for (day = 1; day < 15; day++) { do 

Why do you have both for() and do() (presumably do-while() )? 为什么同时具有for()do() (大概是do-while() )?

  { printf("What is the temperature high for day #%d? ", day++); 

Do not increment day here, it is already incremented as part of the for loop, otherwise the interpretation of day in rest of the body of the loop is wrong! 在此不要增加day ,因为它已经作为for循环的一部分而增加,否则在循环主体其余部分中对day的解释是错误的!

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

It might be scanf("%d", & temperature[day]); 可能是scanf("%d", & temperature[day]); , because scanf() need the address of the variable. ,因为scanf()需要变量的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM