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++; }
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.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
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)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++; }
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
>>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).
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]