Simple Program For Converting Change to Dollars
All right, I was given an assignment to take the number of pennies, nickels, dimes, quarters, and half dollars from the user and then make a program to count the number of coins, how many cents it adds up to (i.e. 450 cents), and then convert it to dollars and cents (i.e. 4 dollars and 50 cents). I have the coins part working, and now I'm trying to get it to add up to the cents and it just isn't working... Here's what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define pennies_per_dollar 1
#define nickels_per_dollar 5
#define dimes_per_dollar 10
#define quarters_per_dollar 25
#define halfdollars_per_dollar 50
main()
{
int pennies, nickels, dimes, quarters, halfdollars, total_coins, total_cents;
int pennies2, nickels2, dimes2, quarters2, halfdollars2;
printf("How many pennies do you have? ");
scanf("%d", &pennies);
printf("How many nickels do you have? ");
scanf("%d", &nickels);
printf("How many dimes do you have? ");
scanf("%d", &dimes);
printf("How many quarters do you have? ");
scanf("%d", &quarters);
printf("How many half dollars do you have? ");
scanf("%d", &halfdollars);
total_coins = pennies + nickels + dimes + quarters + halfdollars;
pennies2 = pennies * pennies_per_dollar / 100;
nickels2 = nickels * nickels_per_dollar / 100;
dimes2 = dimes * dimes_per_dollar / 100;
quarters2 = quarters * quarters_per_dollar / 100;
halfdollars2 = halfdollars * halfdollars_per_dollar / 100;
total_cents = pennies2 + nickels2 + dimes2 + quarters2 + halfdollars2;
printf("\n");
printf("Your total number of coins is: %d\n", total_coins);
printf("You have %d cents.", total_cents);
system("PAUSE");
}