Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <math.h>
- int get_amount(void);
- int main(void)
- {
- // Get user input for Change Owed
- float a = get_amount();
- // Convert to cents
- int cents = round(a * 100);
- // Set coin counter to 0
- int counter = 0;
- while (cents >= 25)
- {
- cents -= 25;
- counter++;
- }
- while (cents >= 10)
- {
- cents -= 10;
- counter++;
- }
- while (cents >= 5)
- {
- cents -= 5;
- counter++;
- }
- while (cents >= 1)
- {
- cents --;
- counter++;
- }
- printf("%i\n", counter);
- }
- // Function: User input for Change Owed
- int get_amount(void)
- {
- float amount;
- do
- {
- amount = get_float("Changed owed: ");
- }
- while (amount < 0);
- return amount;
- }
Advertisement
Add Comment
Please, Sign In to add comment