Hi I am very very new to C, and am working on an assignment for a C programming intro class and I am having a little trouble on my program. The program is supposed to get the users change needed from the input of purchase price and cash tendered, and then print the amount of each coin needed to be given back in change. The problem is that when the program is executed, it gets only to the point of printing the change needed to be given, and then stops. please help me to find my stupid error.
My code is as follows:
Code:
int main(int argc, char **argv) /* Main declaration with arguments */
{
char x;
int 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;
printf("Total Change: $%.2f\n" , cashChange);
//Finds each coin value for the change
while (cashChange >= 00.00){
while (cashChange >= 10.00){
cashChange = cashChange - 10.00 ;
tenDollars = tenDollars + 1;
}
while (cashChange >= 5.00){
cashChange = cashChange - 5.00 ;
fiveDollars = fiveDollars + 1;
}
while (cashChange >= 1.00){
cashChange = cashChange - 1.00 ;
dollars = dollars + 1;
}
while (cashChange >= 0.50){
cashChange = cashChange - 0.50 ;
halfDollars = halfDollars + 1;
}
while (cashChange >= 0.25){
cashChange = cashChange - 0.25 ;
quarters = quarters + 1;
}
while (cashChange >= 0.10){
cashChange = cashChange - 0.10 ;
dimes = dimes + 1;
}
while (cashChange >= 0.05){
cashChange = cashChange - 0.05 ;
nickels = nickels + 1;
}
while (cashChange >= 0.01){
cashChange = cashChange - 0.01 ;
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);
}