Turbo C阵列问题

时间:2011-05-21 06:46:35

标签: c arrays turbo-c

我只是想问一下我的代码。

#define LIM 40

main()
{
       int day=0;
       float temp[LIM];

       clrscr();

       do
       {
               printf("Enter temperature for day %d.", day);
               scanf("%f", &temp[day]);
       }
       while(temp[day++] > 0)
}

我正在使用TurboC,此代码重复要求用户输入温度并将响应存储在数组 temp 中,直到温度为0或更低为止进入。我使用 #define 指令将标识符 LIM 的值设为40,因为我想要这个程序接受任何数量的温度高达40。但它实际上接受高达48 ...我该怎么办才能接受最多40个?

提前致谢

1 个答案:

答案 0 :(得分:2)

将条件更改为以下内容:while (temp[day++] > 0 && day < LIM)