Originally Posted by
Kyeong
Ok, I guess I need to re-write my question.
This is a program which would ask for user input. So how would I know how much of each bill and coin would be needed to give out to the customer? How will the program know? I know myself, but I'm not the program. So that's why I'm asking here how to do it. Do I use if and else statements? Divide each value to determine how much of each bill or coin needs to be given?
Like what I quoted above, how would the program itself know what to print that? That's what I'm trying to make the program do.
A while loop might be useful. Something like this:
(this is not actual code to paste into your program, it's pseudo-code, or "idea" code, to serve as a springboard, only.
Code:
/* I like to convert change_due to all pennies, right here, before this while
loop. That makes it all "homogeneous". (Next week, we'll study Pasteurizing
it, eh? :) )
*/
tener = fiver = one = quarter = dime = nickel = penny = 0;
while(change_due > 0) {
if(change_due >= 1000) {
tener++;
change_due -= 1000;
continue; //key part of the logic, starts the whole loop, all over again.
}
if(change_due >= 500) {
fiver++;
change_due -= 500;
continue;
}
//continue for all denominations of your change, always going biggest to smallest values
} //end of while loop
There are shorter ways of doing this using mod division, but this while loop is
instructive, as well.
To print it out, two print statements.
Code:
printf("$10.00 %d \n$5.00 %d \n$1.00 %d", tener, fiver, one);
//repeat this form of print statement, for the coins change.