Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <math.h>
- #include <stdio.h>
- int main (void)
- {
- float dollars;
- int counter = 0;
- //a loop to take the user input
- do
- {
- printf("how much change is owed? ");
- dollars = GetFloat();
- }
- while (dollars <= 0 );
- //changing from float to int
- int cent = round(dollars * 100);
- //loops to collect input and give number of coins left.
- while (cent >= 25)
- {
- counter ++;
- cent = cent - 25;
- }
- while(cent > 10)
- {
- counter++;
- cent = 10 - cent;
- }
- while (cent > 5)
- {
- counter++;
- cent = 5 - cent;
- }
- while (cent > 1)
- {
- counter++;
- cent = 1 - cent;
- }
- printf("%d\n",counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement