1

I'm trying to make an if statement with a quotient.

totalGrades is a calculation of 5 numbers maxGrades is a calculation of the maximum grades of 5 classes ( maximum grades is always 39 )

I want to make a if statement that shows "Not enough points to graduate!" only if the totalGrades is below 5/6 of maxGrades

The quotient is not working and when I run it always prints Enough points to graduate even if totalGrades is below 5/6 of

if (totalGrades < 5 / 6)
meldingJaar = "Not enough points to graduate!";
else
meldingJaar = "Enough points to graduate!";

I tried this but this doesn't work

if (totalGrades % 82 <= maxGrades)
John Doe
  • 47
  • 1
  • 7
  • "if the totalGrades is below 5/6 of maxGrades" would be `if(totalGrades < maxGrades * 5/6)`, but you're also in java, so 5/6 is zero due to int division. – Mike 'Pomax' Kamermans Nov 15 '14 at 23:37
  • Are you using integers or floating point? Also, provide some concrete examples with numbers to demonstrate the problem. "is not working" is insufficient information for anyone to help. – Jim Garrison Nov 15 '14 at 23:38
  • if(totalGrades < maxGrades * 5/6) worked for me, thanks Mike – John Doe Nov 15 '14 at 23:43

1 Answers1

1

You're encountering integer division. Try 5f / 6 to invoke floating-point division.

Marcus McLean
  • 1,306
  • 2
  • 13
  • 24