Turbo C Array Question

前提是你 提交于 2019-12-02 17:32:29

问题


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 accept 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


回答1:


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



来源:https://stackoverflow.com/questions/6080126/turbo-c-array-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!