+ 4

Help pls

1st Apr 2023, 4:36 PM
D1M3
D1M3 - avatar
9 Respuestas
+ 5
Read the task description again carefully.. You may be misunderstood it. If popsicles evenly distributed to siblings then print give away otherwise eat them yourself.
1st Apr 2023, 4:48 PM
Jayakrishna 🇮🇳
+ 4
If input 3 9 then you can give 3 siblings each 3 popsicles. If input is 4 10 then you cannot evenly distribute because for each 4 siblings giving 2 popsicles will be 4*2=8 but 10-8 = 2 left so you can't give away. Eat them your self. Hope now you can understand, what is the task and mistake in your code... edit: GamerGeil Hd if the task is different one which i know (above) , then pls add description...
1st Apr 2023, 5:03 PM
Jayakrishna 🇮🇳
+ 2
#include <iostream> using namespace std; int main() { int siblings, popsicles; //take input cin >> siblings >> popsicles; //check for invalid input if(popsicles <= 0) { cout << "eat them yourself" << endl; return 0; } else if(popsicles >= 2) { cout << "give away" << endl; return 0; } //calculate and output result cout << popsicles % siblings << endl; return 0; }
1st Apr 2023, 4:36 PM
D1M3
D1M3 - avatar
+ 2
Thx btw i got it so: #include <iostream> using namespace std; int main() { int siblings, popsicles; cin >> siblings >> popsicles; if (popsicles % siblings == 0) { cout << "give away" << endl; } else { cout << "eat them yourself" << endl; } return 0; }
1st Apr 2023, 7:06 PM
D1M3
D1M3 - avatar
+ 1
But i did i have else if
1st Apr 2023, 4:52 PM
D1M3
D1M3 - avatar
+ 1
Should i do: else { cout << "give away" << endl; return 0; }
1st Apr 2023, 4:54 PM
D1M3
D1M3 - avatar
+ 1
Thx
1st Apr 2023, 5:48 PM
D1M3
D1M3 - avatar
+ 1
👍 You're welcome..
1st Apr 2023, 7:33 PM
Jayakrishna 🇮🇳
0
С чем помочь?
3rd Apr 2023, 3:58 PM
Алексей