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;
- int q = 0,d = 0,n = 0,p = 0;
- do
- {
- dollars = get_float("How much change is owed to you?");
- }
- while (dollars < 0);
- int cents = round(dollars * 100);
- printf("you entered: %d\n", cents);
- while(cents-25>=0)
- {
- q=q+1;
- cents=cents-25
- }
- while(cents-10>=0)
- {
- d=d+1;
- cents=cents-10
- }
- while(cents-5>=0)
- {
- n=n+1;
- cents=cents-5
- }
- while(cents-1>=0)
- {
- p=p+1;
- cents=cents-1
- }
- printf("25 cents coins = %d /n 10 cents coins = %d /n 5 cents coins = %d /n 1 cent coins = %d /n",q,d,n,p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement