+ 2

Need help with what logical operators to use. I've used the modular but it only passed 1 case.

Volunteers have been divided into 5 groups with equal number of members. If any group has fewer than 5 people, more volunteers must be recruited to fill the positions. Write a program that takes the number of volunteers and outputs to the console how many volunteers need to be hired to have 5 equal groups. Sample Input 24 Sample Output 1 Explanation The nearest number to 24 that is multiple of 5 is 25, so we need 1 more volunteer (24+1=25) to get 5 equal groups.

3rd Nov 2020, 10:42 AM
Andre Vargas
Andre Vargas - avatar
7 Respostas
+ 6
if volunteers % 5 results in remainder zero ,then all volunteers got divided equally in 5 groups If remainder is not 0 ,then 5-remainder will tell you how many extra volunteers are needed
3rd Nov 2020, 10:47 AM
Abhay
Abhay - avatar
+ 5
3rd Nov 2020, 12:36 PM
Abhay
Abhay - avatar
+ 4
function main() { var numberVolunteers = parseInt(readLine(), 10) // find the remainder of Volunteers when you divide them by 5 var remainder = numberVolunteers % 5 // if it's equal to 0 print 0, if it's not equal to 0 print the result of subtract the remainder from 5 result = (remainder == 0) ? console.log(0) : console.log(5 - remainder) }
2nd Sep 2021, 5:06 PM
Ali Bahaeldin Makkawi
Ali Bahaeldin Makkawi - avatar
+ 4
//another solution by if function main() { var numberVolunteers = parseInt(readLine(), 10) var remainder = numberVolunteers % 5 if( remainder == 0){ console.log(0) } else{ console.log(5 - remainder) } }
2nd Sep 2021, 5:07 PM
Ali Bahaeldin Makkawi
Ali Bahaeldin Makkawi - avatar
+ 2
Thank you Abhay! I figured it out once you wrote it out in a way I could fully understand.
3rd Nov 2020, 11:37 AM
Andre Vargas
Andre Vargas - avatar
+ 1
I've done exactly this but it's still not accepted.
9th May 2021, 6:50 AM
Cornelius Ogunjeminiyi
Cornelius Ogunjeminiyi - avatar
+ 1
If any group has fewer than 5 people, more volunteers must be recruited...? Isnt this setting a min of 5 groups of 5? One of the tests is input of 14, with expected output of 1. Poorly worded question or?
15th May 2021, 7:24 PM
Tomas