+ 3

popsicles code coach

https://www.sololearn.com/coach/3?ref=app hey i almost done with this code but 2/5 case i failed please help me understand how actually its work how can you get the output of 2.5 what exactly the formula https://code.sololearn.com/cfiNsrs1Kve8/?ref=app

27th Dec 2019, 5:39 PM
AxeCodex
AxeCodex - avatar
5 Réponses
+ 6
Shouldn't this logic do the job? if(popsicles%siblings == 0) cout<<"give away"; else cout<<"eat them yourself";
27th Dec 2019, 5:46 PM
Avinesh
Avinesh - avatar
+ 4
I will say candies so don't mind. The candies has to be distributed evenly to the siblings so if even 1 of them gets less or more number of candies then you have to eat them yourself. So if there are 4 siblings and 12 candies then 12%4 is 0. So every one gets equal candies and nothing remains. But if there are 3 siblings and 10 candies then 10%3 is 1. So one sibling will get that extra candy which does not satisfy the condition of equal distribution. Since all the candies has to be distributed, this is how you find whether you give them away or eat it by yourself.
27th Dec 2019, 5:56 PM
Avinesh
Avinesh - avatar
0
Avinesh its work but i dont really understand can you explain?
27th Dec 2019, 5:51 PM
AxeCodex
AxeCodex - avatar
0
The key is if (popsicles % siblings == 0) (sorry I solved it using Java)
10th Sep 2020, 2:10 AM
Rafael D. Algauer
Rafael D. Algauer - avatar
0
Another option - int rez = popsicles % siblings; if (rez != 0){ cout<< "eat them yourself"; } else{ cout<< "give away"; } sometimes there is an error ' instead of "
31st Aug 2021, 4:43 AM
Алексей Выдренков
Алексей Выдренков - avatar