Skip to content

anonymous /gist:5149538

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
Something went wrong with that request. Please try again.