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 dollarInput;
- // Prompt user for input and store it in float variable n.
- do
- {
- dollarInput = get_float("Changed owed?: ");
- }
- //Prompt user for input again if user types a negative number
- while (dollarInput < 0);
- // Round cents to nearest penny with func round
- int cents = round(dollarInput * 100);
- }
- void greedyAlghoritm(int cents){
- int quarters = 0, dimes = 0, nickels = 0, pennies = 0, count = 0;
- //Check for 25c
- while (cents >= 25)
- {
- // Take 25 out of cents and increase variable quarters by one
- cents = cents - 25;
- quarters++;
- }
- // Check for dimes
- while (cents >= 10)
- {
- cents = cents - 10;
- dimes++;
- }
- // Check for nickels
- while (cents >= 5)
- {
- cents = cents - 5;
- nickels++;
- }
- while (cents >= 1)
- {
- cents = cents - 1;
- pennies++;
- }
- // print final answer: how many coins?
- //printf("%i Quarters \n", quarters);
- //printf("%i Dimes \n", dimes);
- //printf("%i Nickels \n", nickels);
- //printf("%i Pennies \n", pennies);
- printf("%i", cents);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement