Created
March 13, 2013 05:10
-
-
Save anonymous/5149538 to your computer and use it in GitHub Desktop.
Penny calculation not working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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