0

Please help worh answer to volunteer teams

Below is the question. I really cant figure out the code usiing boolean or logic operators . If else statements have not beem covered yet so i do t thnk the amswer relieson this. Could someone please help with the answer Thanks 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 empty spots. 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.

20th Mar 2021, 6:21 PM
Leanne Smith
Leanne Smith - avatar
7 ответов
+ 3
Leanne Smith Just get reminder (rem = number % 5) and check if reminder is greater than 0 then subtract reminder from 5 and print difference. But if reminder is 0 then just print 0
20th Mar 2021, 7:06 PM
A͢J
A͢J - avatar
+ 2
hi! do you have a code for trying to solve this problem?
20th Mar 2021, 7:28 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Can anyone see where my mistake is? Thanks function main() { var numberVolunteers = parseInt(readLine(), 10) var peopleNeeded = numberVolunteers%5 if peopleNeeded > 0 { console.log(peopleNeeded) } else { console.log("no one else needed.") } }
7th Jun 2021, 4:39 PM
Chris
Chris - avatar
+ 1
this is the solution to the code above var input = window.prompt("enter the number of volunteers"); outputA = 25 - input; outputB = 5 - (input % 5); console.log(! input < 25 ? outputB : outputA);
4th Aug 2021, 12:01 PM
Macaulay Precious
Macaulay Precious - avatar
+ 1
var p = parseInt(prompt()); function o(z) { var a = z%5; var b = 5-a; console.log(b) return b; } o(p);
25th Mar 2022, 3:57 AM
Dev@ng
0
var volunteers = prompt("Number of volunteer"); // To take the vol number ; var notEqual = volunteers%5; // To know how many person not in group ; var makeEqual = 5 - notEqual; // To know how many person to make all group equal ; var eachGroup = volunteers/5; // To know how many person in each group (volunteers % 5 === 0 ) ? console.log("All group equal and have " + eachGroup + " person") : console.log("You have " + notEqual + " not in group so still need " + makeEqual + " persons to make all groups equal" );
24th Mar 2021, 12:01 AM
Toka ElTorkey
0
Leanne Smith Boolean: not needed. If statement: strictly speaking not needed - you can use a ternary instead for example. Logical operators: not needed, buy you'll need this % which is an arithmetic operator called the remainder operator. 🅘🅜 🅰🅹 !!! has laid out the steps nicely I think Sololearn have badly worded the question. It makes it sound like there are 5 groups ("Volunteers have been divided into 5 groups...") but the answer doesn't need to handle that. All it needs to handle is that each group must have a number of people that's divisible by 5. So, if the initial number of volunteers is 11, the answer should be 4 because that allows you to get to 15 which would make 3 5-person groups.
24th Mar 2021, 1:55 AM
CamelBeatsSnake
CamelBeatsSnake - avatar