Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<cs50.h>
- #include<math.h>
- int main(void)
- {
- {
- float x;
- //Prompt user for change owed
- {
- do
- {
- x = get_float("Change owed:");
- }
- while (x < 0);
- }
- int coins;
- // to store change owed
- int n ;
- //Convert float to integer
- n = round(x * 100);
- //Count the number of coins
- coins = 0;
- //Number of Quarters
- while (n >= 25)
- {
- coins += 1;
- n = n - 25;
- }
- //Number of Dimes
- while (n >= 10)
- {
- coins += 1;
- n = n - 10;
- }
- //Number of Nickels
- while (n >= 5)
- {
- coins += 1;
- n = n - 5;
- }
- //Number of Pennies
- while (n >= 1)
- {
- coins += 1;
- n = n - 5;
- }
- // Display number of coins
- printf("%d\n", coins);
- }
- }
Add Comment
Please, Sign In to add comment