Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <cs50.h>
- int main(void)
- {
- float change;
- float remains;
- float quarter = 0.25;
- float dime = 0.10;
- float nickel = 0.05;
- float penny = 0.01;
- int numberOfCoins = 0;
- do
- {
- printf("How much change is owed?: ");
- change = get_float();
- }
- while(change <= 0);
- remains = change;
- while(remains >= quarter)
- {
- remains = remains - quarter;
- numberOfCoins++;
- }
- while(remains >= dime)
- {
- remains = remains - dime;
- numberOfCoins++;
- }
- while(remains >= nickel)
- {
- remains = remains - nickel;
- numberOfCoins++;
- }
- while(remains >= penny)
- {
- remains = remains - penny;
- numberOfCoins++;
- }
- printf("%d\n", numberOfCoins);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement