Advertisement
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 cash;
- int cents;
- int counter =0;
- do{
- printf("O hai! How much change is owed?\n");
- cash = get_float();
- }
- while (cash<0);
- // take input the amount of cash owned
- cents = cash * 100;
- cents = round(cash*100);
- if (cents % 25 == 0)
- {
- counter += round(cents / 25);
- cents = 0;
- }
- else if ( cents != 0 && cents % 25 != cents) {
- counter += round(cents / 25);
- cents = cents % 25;
- }
- if (cents != 0 && cents % 10 == 0)
- {
- counter += round(cents / 10);
- cents = cents % 10;
- }
- else if (cents != 0 && cents % 10 != cents)
- {
- counter += round(cents/10);
- cents = cents % 10;
- }
- //cents = 6
- if (cents != 0 && cents % 5 == 0)
- {
- counter += round(cents/5);
- }
- else if ( cents != 0 && cents % 5 != cents)
- {
- counter += round(cents/5);
- cents = cents % 5;
- }
- else
- {
- //counter += cents;
- }
- counter += cents;
- printf("%i\n", counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement