Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Created June 22, 2016 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuddyBootsCode/be50c9036dccb07556d92a14cb67cf91 to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/be50c9036dccb07556d92a14cb67cf91 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<math.h>
#include<cs50.h> // only for CS50 IDE
int main (void)
{
float change, rnd;
int quarters, dimes, nickles, pennies, coins;
do
{
printf("How much change is owed?\n");
rnd = GetFloat(); // scanf("%fl", &rnd); for non CS50 program
change = roundf(rnd*100);
} while (change <= 0 );
quarters = (change / 25);
dimes = ((int)change % 25)/10;
nickles = (((int)change % 25) %10)/5;
pennies = ((((int)change % 25) %10) %5)/1;
coins = quarters + dimes + nickles + pennies;
printf("%d\n", coins);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment