簡體   English   中英

C編程不斷崩潰

[英]C Programming Keeps Crashing

我似乎無法弄清楚出了什么問題。 我得到了一個干凈的編譯器,但是輸入第一個數字后,它崩潰了。

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

任何幫助,甚至暗示,將不勝感激!

您還沒有顯示的定義temerature ,但根據您的使用情況,

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

幾乎應該是

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

當您要從用戶輸入內容時,必須提供&登錄scanf()函數,如下所示,

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

您丟失了&登錄到scanf()函數。 添加它,您的問題將得到解決。

int和int *不匹配。

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

代替

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

為什么同時具有for()do() (大概是do-while() )?

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

在此不要增加day ,因為它已經作為for循環的一部分而增加,否則在循環主體其余部分中對day的解釋是錯誤的!

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

可能是scanf("%d", & temperature[day]); ,因為scanf()需要變量的地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM