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 );
- //changing from float to int.
- int cent = round(dollars * 100);
- //loops to collect input and give number of coins left.
- while (dollars >= 25)
- counter ++;
- quarters --;
- dollars = dollars / 5;
- dollars = dollars % 25;
- while (dollars >= 10)
- counter++;
- dimes--;
- dollars = dollars % 10;
- while (dollars >= 5)
- counter++;
- nickel--;
- dollars = dollars / 5;
- dollars = dollars % 5;
- while (dollars >= 1)
- counter++;
- penny --;
- dollars = dollars / 1;
- dollars = dollars % 1;
- printf("i have %d coins ", counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment