Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2013 05:10
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 anonymous/5149538 to your computer and use it in GitHub Desktop.
Save anonymous/5149538 to your computer and use it in GitHub Desktop.
Penny calculation not working.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
#define QUARTER 25 //quarter converted to 25 cents
#define DIME 10 //dime converted to 10 cents
#define NICKLE 5 //nickle converted to 5 cents
#define PENNY 1 //penny converted to 1 cent
int main()
{
printf("Please deposit your coins?\n");
float coin_amount = GetFloat();
int amount_converted = coin_amount * 100;
int quarters = amount_converted / QUARTER;
while ( amount_converted >= QUARTER )
{
amount_converted -= 25;
}
int dimes = amount_converted / DIME;
while ( amount_converted >= DIME )
{
amount_converted -= 10;
}
int nickles = amount_converted / NICKLE;
while ( amount_converted >= NICKLE )
{
amount_converted -= 5;
}
int pennies = amount_converted / PENNY;
printf("Quarters\t%d\n", quarters);
printf("Dimes\t\t%d\n", dimes);
printf("Nickles\t\t%d\n", nickles);
printf("Pennies\t\t%d\n", pennies);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment