I am making a program for a class. The program is supposed to calculate the change needed in coins from the amount given. The problem is that it gets stuck somewhere in the coin sorting loop but I can't figure out why or where. help is appreciated.
Code:
int main(int argc, char **argv) /* Main declaration with arguments */
{
char x;
int multipliedCashChange, pennies = 0, nickels = 0, dimes = 0, quarters = 0 , halfDollars = 0, dollars =0 , fiveDollars = 0 , tenDollars = 0;
float purchasePrice , cashTendered , cashChange;
//collects imput from user and finds the change needed from those two imputs.
printf("Enter the purchase price including cents ($ddd.cc): $");
scanf("%f" , &purchasePrice);
printf("Enter amount of cash tendered including cents ($ddd.cc): $");
scanf("%f" , &cashTendered);
cashChange = cashTendered - purchasePrice;
multipliedCashChange = cashChange * 100;
printf("Total Change: $%.2f\n" , cashChange);
//Finds each coin value for the change
while (multipliedCashChange >= 0){
while (multipliedCashChange >= 1000){
multipliedCashChange = multipliedCashChange - 1000 ;
tenDollars = tenDollars + 1;
}
while (multipliedCashChange >= 500){
multipliedCashChange = multipliedCashChange - 500 ;
fiveDollars = fiveDollars + 1;
}
while (multipliedCashChange >= 100){
multipliedCashChange = multipliedCashChange - 100 ;
dollars = dollars + 1;
}
while (multipliedCashChange >= 50){
multipliedCashChange = multipliedCashChange - 50 ;
halfDollars = halfDollars + 1;
}
while (multipliedCashChange >= 25){
multipliedCashChange = multipliedCashChange - 25 ;
quarters = quarters + 1;
}
while (multipliedCashChange >= 10){
multipliedCashChange = multipliedCashChange - 10 ;
dimes = dimes + 1;
}
while (multipliedCashChange >= 5){
multipliedCashChange = multipliedCashChange - 5 ;
nickels = nickels + 1;
}
while (multipliedCashChange >= 1){
multipliedCashChange = multipliedCashChange - 1 ;
pennies = pennies + 1;
}
}
//prints the value of each coin
printf("Ten Dollar Coins: %d\n" , tenDollars);
printf("Five Dollar Coins: %d\n" , fiveDollars);
printf("One Dollar Coins: %d\n" , dollars);
printf("Half Dollar Coins: %d\n" , halfDollars);
printf("Quarter Coins: %d\n" , quarters);
printf("Dime Coins: %d\n" , dimes);
printf("Nickel Coins: %d\n" , nickels);
printf("Penny Coins: %d\n" , pennies);
printf("[Done]\n");
//exits program
printf(" \n");
scanf("%c",&x);
printf(" \n");
printf("Press any key to continue . . . ");
scanf("%c",&x);
exit(0);
}