We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Since the value 67 is greater than 38 and the difference between value and next multiple of 5 (i.e. 70) is 3 (70 - 67) which is not less than 3, it will not be rounded. Hence, 67 i.e. 'grade' value is printed.
However, for the value 68, the difference is 2 (70 - 68) < 3, so the grade will be rounded to the next multiple by the calculation :
grade + (5 - (grade % 5)) = 68 + (5 - (68 % 5))
= 68 + (5 - 3)
= 68 + 2
= 70 (next multiple of 5)
Hope this helps! :)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Grading Students
You are viewing a single comment's thread. Return to all comments →
The rules for rounding off is stated as follows :
Since the value 67 is greater than 38 and the difference between value and next multiple of 5 (i.e. 70) is 3 (70 - 67) which is not less than 3, it will not be rounded. Hence, 67 i.e. 'grade' value is printed.
However, for the value 68, the difference is 2 (70 - 68) < 3, so the grade will be rounded to the next multiple by the calculation :
grade + (5 - (grade % 5)) = 68 + (5 - (68 % 5))
= 68 + (5 - 3)
= 68 + 2
= 70 (next multiple of 5)
Hope this helps! :)