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;
- //a loop to take the user input
- do
- {
- printf("how much change is owed? ");
- dollars = GetFloat();
- }
- while (dollars <= 0 );
- int cent = round(dollars * 100);
- //loops to collect input and give number of coins left.
- while (cent >= 25)
- {
- counter++;
- cent = cent - 25;
- }
- while(dimes >= 10)
- {
- counter++;
- cent = cent - 10;
- }
- while (nickel >= 5)
- {
- counter++;
- cent = cent - 5;
- }
- while (penny >= 1)
- {
- counter++;
- cent = cent - 1;
- }
- printf("i have %d coins\n",counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement