Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- int get_cents(void);
- int calculate_quarters(int cents);
- int calculate_dimes(int cents);
- int calculate_nickels(int cents);
- int calculate_pennies(int cents);
- int main(void)
- {
- // Ask how many cents the customer is owed
- int cents = get_cents();
- // Calculate the number of quarters to give the customer
- int quarters = calculate_quarters(cents);
- cents = cents - quarters * 25;
- // Calculate the number of dimes to give the customer
- int dimes = calculate_dimes(cents);
- cents = cents - dimes * 10;
- // Calculate the number of nickels to give the customer
- int nickels = calculate_nickels(cents);
- cents = cents - nickels * 5;
- // Calculate the number of pennies to give the customer
- int pennies = calculate_pennies(cents);
- cents = cents - pennies * 1;
- // Sum coins
- // int coins = quarters + dimes + nickels + pennies;
- // Print total number of coins to give the customer
- printf("the change due is \n %i quarters \n %i dimes \n %i nickels \n %i pennies\n",
- quarters, dimes, nickels, pennies);
- }
- int get_cents(void)
- {
- int cents;
- do
- {
- cents = get_int("how many cents owed?\n");
- }
- while (cents >100 || cents <2);
- return cents;
- }
- int calculate_quarters(int cents)
- {
- //i feel like this was probalby the intended solutions but is completely useless
- // if (cents >= 75)
- // {
- // quarters = 3;
- // }
- // else if (cents <= 74 && cents >= 50)
- // {
- // quarters = 2;
- // }
- // else if (cents <= 49 && cents >= 25)
- // {
- // quarters = 1;
- // }
- // else
- // {
- // quarters = 0;
- // }
- return cents / 25;
- }
- int calculate_dimes(int cents)
- {
- // TODO
- return cents / 10;
- }
- int calculate_nickels(int cents)
- {
- // TODO
- return cents / 5;
- }
- int calculate_pennies(int cents)
- {
- // TODO
- return cents / 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement