+ 1

I am unable to this question in C language

You have a box of popsicles and you want to give them all away to a group of brothers and sisters. If you have enough left in the box to give them each an even amount you should go for it! If not, they will fight over them, and you should eat them yourself later. Task Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or if you shouldn't mention the popsicles at all. Input Format Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles that you have left in the box. Output Format A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself. Sample Input 3 9

7th Feb 2021, 3:23 PM
Vishal
Vishal - avatar
12 Antworten
+ 5
Vishal so your code is very interesting. it works sometimes and not others, depending on the hidden inputs. what you need to do is change your condition if (popsicles/2 == siblings && siblings *2 == popsicles) what you need to do is divide the number of popsicles by the number of siblings. make sure you use this % instead of / that will return the remainder. if(popsicles % simblings == 0)
7th Feb 2021, 3:57 PM
Brain & Bones
Brain & Bones - avatar
+ 3
The question doesn't want you to give the popsicles away only when you can distribute exactly 2 to each of the siblings. According to the question statement, string "give away" should be displayed when you can give all the popsicles to siblings such that each one of them get equal number of popsicles with them. For example : for a case like 5 5 Your current program fails to give correct output.
7th Feb 2021, 4:07 PM
Arsenic
Arsenic - avatar
+ 2
please show your attemps. and say which part you are having trouble with
7th Feb 2021, 3:41 PM
Brain & Bones
Brain & Bones - avatar
+ 2
#include <stdio.h> int main() { int siblings, popsicles; scanf("%d\n", &siblings); scanf("%d\n", &popsicles); //your code goes here if (popsicles/2 == siblings && siblings *2 == popsicles) { printf ("give away"); } else { printf ("eat them yourself"); } return 0; }
7th Feb 2021, 3:44 PM
Vishal
Vishal - avatar
+ 1
Caleb: thanks man I have asked this question cause I was scratching my head for 15 minutes and was unable to do So just asked it also, I am a beginner not so good at programing When did you started programing??? Are u a high school student???
7th Feb 2021, 4:16 PM
Vishal
Vishal - avatar
+ 1
Vishal no problem. i have been coding for a couple years. yes. Happy Coding. 😉
7th Feb 2021, 4:27 PM
Brain & Bones
Brain & Bones - avatar
7th Feb 2021, 3:45 PM
Vishal
Vishal - avatar
0
Above link has the question
7th Feb 2021, 3:46 PM
Vishal
Vishal - avatar
0
Vishal ok give me i few minutes and i will help you.
7th Feb 2021, 3:47 PM
Brain & Bones
Brain & Bones - avatar
0
Caleb Could you tell me how many couple of years😁 I am just little curious
7th Feb 2021, 4:32 PM
Vishal
Vishal - avatar
0
Vishal Just one couple. 😁 I have been coding for about two years.
7th Feb 2021, 4:42 PM
Brain & Bones
Brain & Bones - avatar
0
Thank God got the answer after saying couple😁
7th Feb 2021, 5:05 PM
Vishal
Vishal - avatar