I don't get a compilation error, but if I enter in -1 as a number the program just continues to ask for the grade over and over again.Code:while(grade[i] != -1)
{
printf("GRADE: ");scanf("%f",&grade[i]);
i++;count++;
}
Printable View
I don't get a compilation error, but if I enter in -1 as a number the program just continues to ask for the grade over and over again.Code:while(grade[i] != -1)
{
printf("GRADE: ");scanf("%f",&grade[i]);
i++;count++;
}
Is grade an array of floats or ints?
As you've incremented i, the test within the while won't be looking at the number you've just entered.
You are reading a value into grade[ i ], you then increment i past the read in value, and compare the wrong grade (which is zero)Quote:
Originally posted by kinghajj
I don't get a compilation error, but if I enter in -1 as a number the program just continues to ask for the grade over and over again.Code:while(grade[ i ] != -1)
{
printf("GRADE: ");scanf("%f",&grade[ i ]);
i++;count++;
}
>>and compare the wrong grade (which is zero)
Where'd you get the idea it's zero? More than likely it's undefined (at least, that's my guess).