Not quite. That's not going to evaluate the way you think it will.
if ( (90 <= average) <= 100)
Note the extra parenthesis to indicate the order of evaluation.
90 <= average will result in a bool (true or false). That result will then be compared to 100, which will always be true.
This is my code. I am having trouble with the categories. For example if I enter an 85 for the input it brings up A and B categories. What am I doing wrong?
okay i changed were 60 is now 59. So when i enter for example 100 i am getting invalid data which that is what it wants, but i also am getting an A and "you fail". What am i doing wrong there? The code is below. This is what i have.
for example 100 i am getting invalid data which that is what it wants, but i also am getting an A and "you fail".
This is one of the potential pitfalls of using two tests in each if statement. That is, you may end up with gaps where some values are not handled, or with overlaps where some value is handled more than once (both of which you have in your case). With care you can resolve these issues, but it is creating extra work for yourself, since each condition is tested more than once.
I have done some minor changes like removed last else condition and added some{} after if loop.
here is the code which works fine and gives exact output at condition=100
I'd still say it is better to remove the redundant code. At line 12,
elseif (average >= 90 && average <= 100)
it is already known that average must no greater than 100 (because that was eliminated at line 8), thus there is no need for the clause && average <= 100.
The same would apply at lines 16 and 20. && average <= 89 and && average <= 79 are redundant and should be removed.
This simplification also allows the code to work correctly for values such as 89.5 with no other changes.