+ 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
5 Answers
+ 6
Shouldn't this logic do the job?
if(popsicles%siblings == 0)
cout<<"give away";
else
cout<<"eat them yourself";
+ 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.
0
Avinesh its work but i dont really understand can you explain?
0
The key is if (popsicles % siblings == 0) (sorry I solved it using Java)
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 "