Advertisement
Guest User

Burk

a guest
Apr 7th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4.  
  5. int main(void)
  6. {
  7.     float dollarInput;
  8.         // Prompt user for input and store it in float variable n.
  9.     do
  10.     {
  11.         dollarInput = get_float("Changed owed?: ");
  12.     }
  13.         //Prompt user for input again if user types a negative number
  14.     while (dollarInput < 0);
  15.         // Round cents to nearest penny with func round
  16.     int cents = round(dollarInput * 100);
  17.     
  18. }
  19.  
  20. void greedyAlghoritm(int cents){
  21.  
  22.     int quarters = 0, dimes = 0, nickels = 0, pennies = 0, count = 0;
  23.  
  24.         //Check for 25c
  25.     while (cents >= 25)
  26.     {
  27.         // Take 25 out of cents and increase variable quarters by one
  28.         cents = cents - 25;
  29.         quarters++;
  30.     }
  31.         // Check for dimes
  32.     while (cents >= 10)
  33.     {
  34.         cents = cents - 10;
  35.         dimes++;
  36.     }
  37.         // Check for nickels
  38.     while (cents >= 5)
  39.     {
  40.         cents = cents - 5;
  41.         nickels++;
  42.     }
  43.     while (cents >= 1)
  44.     {
  45.         cents = cents - 1;
  46.         pennies++;
  47.     }
  48.     // print final answer: how many coins?
  49.     //printf("%i Quarters \n", quarters);
  50.     //printf("%i Dimes \n", dimes);
  51.     //printf("%i Nickels \n", nickels);
  52.     //printf("%i Pennies \n", pennies);
  53.     printf("%i", cents);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement