I am having trouble on a hw problem. I must compute total amount a user inputs into cents. And display the amount needed in quarters, dimes, ect. But am having difficulty with the division portion. Here is my code
First, When working with money instead of using int you use float so it can give you the values beyond the dot Example:
1 2
INT A = 1; // cannot have a value like this 6.98
FLOAT B = 9.99; // CAN have values like this > 9.9 < AND this > 13 <
{Still Needed in this case if inputted goes below 100 in the code below}
EDIT: Why do you divide nickels by 1 if its gonna return the same value again ???, Why do you put % instead of / ??? Why do you divide from the last obtained value instead of keep dividing by Total ??? i think im gonna give you a sample code-- (Status: Working)
okay I will try that. Right now I have it compiled and it runs great SOMEWHAT. It asks for an amount I enter lets say " 100 " but when it computes i get 0 for Quarters/Dimes/Nickels/Pennies. so where is the computation going wrong?
int total_cents = ...;
int dollars = total_cents / 100; //integer division, will truncate the quotient
total_cents %= 100; //remove the money added to dollars from total_centsint quarters = total_cents / 25;
total_cents %= 25; //remove all quarters from total_centsint dimes = total_cents / 10;
total_cents %= 10; //remove all dimes
int nickels = total_cents / 5;
total_cents %= 5; //remove all nickels
int pennies = total_cents; //add remaining cents to pennies, no need to divide by 1
total_cents = 0; //same as total_cents %= 1;