0
Code coach popsicles challenge
//mycode: #include <stdio.h> int main() { int siblings, popsicles; scanf("%d", &siblings); scanf("%d", &popsicles); //your code goes here if (siblings && popsicles ==0){ printf("give away"); } else{ printf("eat them yourself"); } return 0; } My code fails in second step and I don't know what operators or functions should I use please someone give me a clue...
12 Respuestas
+ 3
> You confused popsicles and siblings. We need the remaining popsicles, not the remaining siblings.
Suppose
siblings = 2
popsicles = 7
Compare:
siblings % popsicles = 2 % 7
popsicles % siblings = 7 % 2
The order matters.
+ 2
If the number is evenly divisible by the number of siblings, we are supposed to give the popsicles to them.
Hence, we need to find out if popsicles / siblings is 0 (evenly divisible) or not. This is also called integer division or modulo or "division with remainders". We check if the remainder is 0 or not. In C, there is a dedicated modulo operator: %.
+ 2
> In C, there is a dedicated modulo operator: %.
+ 2
You confused popsicles and siblings. We need the remaining popsicles, not the remaining siblings.
0
Lisa yes got some let me try
0
if (siblings / popsicles ==0){
printf("give away");
}
else{
printf("eat them yourself");
}
return 0;
}
Can't get it till😕
0
Yes if I use (siblings % popsicles==0)
// Still gives error.. I'm missing something 😭
0
Please can you level up your hint one more step please 🥺
0
I know I've have find that popsi && siblings should have a condition where both variable should be able to divided by 2 but I'm weak in math po😢
0
Lisa can you show me the code answer 🙂
0
#include <stdio.h>
int main() {
int siblings, popsicles;
scanf("%d %d", &siblings, &popsicles);
//your code goes here
if (siblings % popsicles ==0){
printf("give away");
}
else{
printf("eat them yourself");
}
return 0;
}
// Please help
0
Lisa yeah thank you it's done ✅😅💝