Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <math.h>
- #include <stdio.h>
- int main (void)
- {
- float dollars;
- int quarters = 0;
- int dimes = 0;
- int penny = 0;
- int nickel = 0;
- int counter = 0;
- //a loop to take the user input
- do
- {
- printf("how much change is owed? ");
- dollars = GetFloat();
- }
- while (dollars <= 0 );
- int cent = round(dollars * 100);
- //loops to collect input and give number of coins left.
- while (quarters >= 25)
- {
- counter++;
- quarters = cent - 25;
- while(dimes >= 10)
- counter++;
- dimes = cent - 10;
- while (nickel >= 5)
- counter++;
- nickel = cent - 5;
- //dollars = cent / 5;
- nickel = cent % 5;
- while (penny >= 1)
- counter++;
- penny = cent - 1;
- printf("i have %d coins\n",counter);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement