I need to query the user for the amount owed and the amount received. I then must calculate the change due and display it in the form of dollars, quarters, dimes, nickels and pennies. I need to use at least 4 reference parameters within the code as well. The code looks good to me, but for some reason the calculations just spit out garbage. Any suggestions?
Code:
/*Program to determine amount of change due
Nov. 4, 2005
Language: C (gcc target)
*/
#include <stdio.h>
#define dollar 100
#define quarter 25
#define dime 10
#define nickel 5
/*Function prototypes*/
void fourth (int *amount2);
void tenth (int *amount3);
void twentieth (int *amount4);
void hundredth (int *amount5);
int main(void)
{ double total, payment;
int amt, amt2, dollars;
printf("Enter amount of money due: ");
scanf("%d", &total);
printf("Enter amount of money given: ");
scanf("%d", &payment);
amt=(payment-total)*100;
dollars=amt/dollar;
printf("%d dollars in change due ",dollars);
amt2=amt-(dollars*100);
fourth(&amt2);
return 0;
}
void fourth (int *amount2)
{ int quarters, amt3;
quarters=*amount2/quarter;
printf("\n%d quarters in change due ",quarters);
amt3=*amount2-(quarters*quarter);
tenth(&amt3);
return;
}
void tenth (int *amount3)
{ int dimes, amt4;
dimes=*amount3/dime;
printf("\n%d dimes in change due ",dimes);
amt4=*amount3-(dimes*dime);
twentieth(&amt4);
return;
}
void twentieth (int *amount4)
{ int nickels, amt5;
nickels=*amount4/nickel;
printf("\n%d nickels in change due ",nickels);
amt5=*amount4-(nickels*nickel);
hundredth(&amt5);
return;
}
void hundredth (int *amount5)
{ int pennies;
pennies=*amount5;
printf("\n%d pennies in change due ",pennies);
return;
}