Advertisement
JiriKiner

cash

Aug 15th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. // Program will calculate the minimum number of coins which should be returned after giving a specific value using the modulo math
  2.  
  3. #include <stdio.h>
  4. #include <cs50.h>
  5. #include <math.h>
  6.  
  7. int main(void)
  8. {
  9.     // Declaring of the variable dollars
  10.     float dollars = 0;
  11.     // Do while loop to get a positive input from the user
  12.     do
  13.     {
  14.         // Asking the user for an input
  15.         dollars = get_float("Change owed: ");
  16.     }
  17.     // Checking if the input is more than 1 penny
  18.     while (dollars < 0.009);
  19.     {
  20.         // Round dollars to pennies
  21.         int change = round(dollars * 100);
  22.         // Calculate the number of each coin
  23.         int quarters = change / 25;
  24.         int dimes = (change % 25) / 10;
  25.         int nickels = ((change % 25) % 10) / 5;
  26.         int pennies = (((change % 25) % 10) % 5) / 1;
  27.         // Adding the coins together
  28.         int coins = quarters + dimes + nickels + pennies;
  29.         // Printing the number of coins
  30.         printf("%i\n", coins);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement