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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top