im taking c programming and i have to get my program to say how many quartes dimes nickels and pennies are in a certain value... 3 different times... i get the display to look right, but the correct values never come across... can anyone help... here is what i have so far.
Any help would be appreciated i have been stuck for a few days on this...
Code:
#include <stdio.h>
int main()
{
void change(float, int *, int *, int *, int *); /*Prototype*/
int quarters, dimes, nickels, pennies;
float firstnum = 1.88;
float secnum = 0.32;
float thirdnum;
change(firstnum, &quarters, &dimes, &nickels, &pennies);/*Call to the Function*/
printf("\nTOTAL VALUE ENTERED: $%f", firstnum);
printf("\n%d Quarters", quarters);
printf("\n%d Dimes", dimes);
printf("\n%d Nickels", nickels);
printf("\n%d Pennies\n", pennies);
change(secnum, &quarters, &dimes, &nickels, &pennies);/*Call to the Function*/
printf("\nTOTAL VALUE ENTERED: $%f", secnum);
printf("\n%d Quarters", quarters);
printf("\n%d Dimes", dimes);
printf("\n%d Nickels", nickels);
printf("\n%d Pennies\n", pennies);
printf("\n Enter amount of money to display in change format:$ ");
scanf("%f", &thirdnum);
change(thirdnum, &quarters, &dimes, &nickels, &pennies);/*Call to the Function*/
printf("\nTOTAL VALUE ENTERED: $%f", thirdnum);
printf("\n%d Quarters", quarters);
printf("\n%d Dimes", dimes);
printf("\n%d Nickels", nickels);
printf("\n%d Pennies\n\n", pennies);
return 0;
}
void change(float money, int *quarters, int *dimes, int *nickels, int *pennies)
{
while(money>=0.25)
{
money-=0.25;
(*quarters++);
}
while(money>=0.1)
{
money-=0.1;
(*dimes++);
}
while(money>=0.05)
{
money-=0.05;
(*nickels++);
}
while(money>=0.01)
{
money-=0.01;
(*pennies++);
}
}