开发者

Turbo C Array Question

I just want to ask something about my code.

#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)
}

I'm using TurboC, this code repeatedly asks the user to enter a temperature and stores the responses in the array temp, until a temperature of 0 or less is entered. I've used a #define directive to give the identifier LIM the value of 40 because I want this program to a开发者_Python百科ccept any number of temperatures up to 40. But It actually accepts up to 48... What should I do so that it could accept up to 40 only?

Thanks in advance


Change the condition in while to the following: while (temp[day++] > 0 && day < LIM).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜