Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- float dollars = 0;
- do
- {
- dollars = get_float("How much do I owe you:");
- }
- while(dollars < 0);
- int cents = round(dollars * 100);
- int quarters = 0;
- if(cents >= 25)
- {
- quarters = cents / 25;
- }
- int dimes = 0;
- if(( cents % 25 ) >= 10)
- {
- dimes = (cents % 25) / 10;
- }
- int remainings = cents - (quarters * 25) - (dimes * 10);
- int nickels = 0;
- if((cents % 25) % 10 >= 5)
- {
- nickels = remainings / 5;
- }
- int pennies = remainings % 5;
- int total = quarters + dimes + nickels + pennies;
- {
- printf("%i\n", total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement