I'm trying to write this program that asks for the purchase amount, the payment amount and then outputs the change in the number of bills and coins. I think I'm missing an 'if' statement for determining the coins. Can someone point me in the right direction with this? Thanks. Here is the code:
Code:
#include <stdio.h>
int main()
{
double p,t;
int coins,bills,change;
int twenties,tens,fives,ones,quarters,dimes,nickels,pennies;
char answer [2];
do
{
printf("\nEnter the purchase amount:");
scanf ("%lf",& p);
printf("\nEnter the payment amount:");
scanf ("%lf",& t);
change=p-t;
bills=(int) change;
twenties=bills/200;
bills=bills%200;
tens=bills/100;
bills=bills%100;
fives=bills/50;
bills=bills%50;
ones=bills/10;
bills=bills%10;
coins=(int)((change-bills)*100);
quarters=coins/25;
coins=coins%25;
dimes=coins/10;
coins=coins%10;
nickels=coins/5;
coins=coins%5;
pennies=coins;
printf("\nYour change will be %d twenties, %d tens, %d fives, %d ones, %d quarters, %d dimes, %d nickels and %d pennies.\n",twenties,tens,fives,ones,quarters,dimes,nickels,pennies);
printf("\nContinue? (Y/N):");
scanf ("%s",&answer);
}
while ((answer[0]=='y') || (answer [0]=='Y'));
return 0;
}