“While” loop isn’t necessary. Your code works perfectly fine without while loop, if you write like this:
scanf("%d", &t);
for (i = 1; i <= t; i++)
If you want multiple “t” inputs you should move your return statement after while brace:
int t, i;
float h, l, w;
while (scanf("%d", &t)) {
for (i = 1; i <= t; i++)
{
scanf("%f%f%f", &l, &w, &h);
if (l <= 20 && w <= 20 && h <= 20)
printf("Case %d: good\n", i);
else
printf("Case %d: bad\n", i);
}
}
return 0;
Also, checking if scanf returned 1 is some kind of protection. scanf returns number of elements filled (int this case 1). If you try to write non-digits it returns 0. You can check what your scanf returns with this or similar code:
printf("%d", scanf("%d", &t));
Good luck!
3
solved What does this statement means on a C program? ” While (scanf (“%d”, &t) ==1)” And why should I write the rest of the program in that while loop? [closed]