Im taking C programming at class and Im doing practice questions in the book.
One of the questions is "Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $20, $10, $5, %1 bills:
The sample is as follows, then what I came up with, followed by my dilemna. You may notice something right away that I may have overlooked when trying my code.
Enter a dollar amount: 93 (user inputted)
$20 bills: 4 $10 bills: 1 $5 bills: 0 $1 bills: 3
what I have so far is:
#include <stdio.h>
int main (void)
{
int cash;
printf("Enter a dollar amount: ");
scanf("%d", &cash);
printf("$20 bills = %d\n", cash / 20);
printf("$10 bills = %d\n", cash / 10);
printf("$5 bills = %d\n", cash / 5);
printf("$1 bills = %d\n", cash / 1);
return 0;
}
Now the dilemma, the book suggests dividing the input number (93) by 20, and since im using "int" instead of "float" that leaves 4 instead of 4.65. Then it suggests reducing the result of that times 20, from 93. leaving 13, and repeating that for each one. so it would be 93/20=4 13/10=1 3/1=3
I cant figure out for the life of me how to get this line printf("$10 bills = %d\n", cash / 10); to recognize the value left by the previous line printf("$20 bills = %d\n", cash / 20);
I had originally tried to put most of it on the 20 bill line. like cash / 20 *20 but it just displayed 80 on that line instead of the next line.
Thanks in advance for any help.