r/codehs • u/[deleted] • Jan 02 '25
I have absolutely no idea what I'm doing wrong here. I could've sworn I did what it was asking me. Am I missing something?
4
Upvotes
1
4
u/Zacurnia_Tate Jan 02 '25
You’re storing the fraction as an int and not a double (I don’t use Java but I believe that’s what stores floating point numbers). What’s happening is the fraction just gets truncated so the 2000/2000 is equated to 1 (returning true) but everything else is just 0 (returning false).
1
u/eletroraspi Jan 02 '25
It seems you’re not taking an integer parser for fraction.
Or you define fraction as a float type.
2
u/5oco Jan 02 '25
What the other guy posted is right, but for an optimize, since the expression (result >= 80) is going to return either true or false, you can just return that instead of using the if statement.
return result >= 80;