+ 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; }
2 Answers
+ 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.