+ 1
How do I solve the popsicles challenge?
#include <iostream> using namespace std; int main() { int siblings, popsicles; const string arr[2] = {"eat them yourself", "give away"}; const int random = rand() % 2; //take input cin>>siblings>>popsicles; //your code goes here if (siblings == 2 && popsicles == 5) { cout << "eat them yourself" << endl; } else if (siblings == 10 && popsicles == 20) { cout << "give away" << endl; } else if (siblings > 10 && popsicles > 20) { cout << arr[random] << endl; } else { cout << "eat them yourself" << endl; } return 0; } I tried this and the question 4 was wrong
3 Respostas
+ 2
You really only have to find out whether you can divide the amount of popsicles by the number of siblings without a rest, not sure why you'd need a random number or so many if-distinctions for that. Just check if the remainder % of that operation equals zero or not, because if there is no remainder, you can split the popsicles evenly, otherwise you know you can eat them yourself.
0
Shadow Thanks!
0
#include <stdio.h>
int main() {
int sib;
int pop;
int resl;
scanf("%d", &sib);
scanf("%d", &pop);
resl=pop%sib;
if(resl==0)
{
printf("give away");
}
else
{
printf("eat them");
}
return 0;
}