+ 2

Help fix c++ code

I tried to complete the ‘popsicles’ code coach and this looked like a foolproof code, but it didn’t work. Can someone tell me the problem I don’t know how to add a code to a question so I’ll paste it here: #include <iostream> using namespace std; int main() { int siblings, popsicles; //take input cin>>siblings>>popsicles; //your code goes here int a; float b; a = siblings/popsicles; b = siblings/popsicles; if(a==b){ cout << "give away"; } else{ cout << "eat them yourself"; } return 0; }

13th Jan 2020, 8:59 PM
Christian0972
2 ответов
+ 2
1. You divided the number of siblings by the amount of popsicles. Are you sure it shouldn't be the other way around? 2. Dividing an integer by another integer will always result in an integer in C++. At least one of the operands needs to be either a float or a double for the division operator to return a floating point value.
13th Jan 2020, 9:26 PM
Shadow
Shadow - avatar
+ 2
Shadow Alexandr Thanks i fixed it
14th Jan 2020, 4:59 PM
Christian0972