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 change, cents;
- int coins = 0;
- // Prompt user for a float
- do
- {
- change = get_float("Please put in change: \n");
- }
- while (change <= 0);
- // Changing dollars to cents
- cents = round (change * 100);
- // Arithmetics
- {
- while (cents >= 25)
- {
- cents -= 25;
- coins++;
- }
- while (cents >= 10)
- {
- cents -= 10;
- coins++;
- }
- while (cents >= 5)
- {
- cents -= 5;
- coins++;
- while (cents >= 1)
- {
- cents -= 1;
- coins++;
- }
- }
- //Output
- printf("Coins needed: %i", coins);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement