Hello all:
I am trying to make my change maker calculate the correct amount of change given and its not calculating at all. My program is compiling and running but I cannot seem to find the issue with my algorithm. Can anyone provide some feed back as to what I'm doing wrong and point me in the right direction?
I know it's a mess but can some please help me make this work?Code:#include <stdio.h> #include <math.h> /* structure definitions */ struct currency { float pennies, nickels, dimes, quarters; int dollars; }; /* end struct currency */ typedef struct currency Currency; int main() { int userPayment, changeAmount, gallons, displayAmount; float value; float total; Currency money; money.pennies = 0.01; money.nickels = 0.05; money.dimes = 0.10; money.quarters = 0.25; money.dollars = 1.00; float unitp; float amount; printf( "Welcome to Dave's paint production. How many gallons would you " "like to order?\nThe unit price is $10.31 a gallon.\n" ); scanf( "%d", &gallons ); printf( "You have chosen to purhase: %d\n", gallons ); printf( "at 10.31 per gallon\n\n" ); unitp = 10.31; printf("\n %.2f", unitp); total = ( gallons * unitp ); printf( "Your total is: $%.2f\n", total ); value = total; amount = value; printf( "\n %.2f", value ); while ( value > 0 ){ amount = amount / 1; value = value - amount; printf( "\n%.2f Dollars", amount ); printf( "\n%2f", value ); amount = value / 0.25; value = value - (amount * 0.25 ); if ( amount > 0 ) printf( "\n%.2f Quarters", amount ); printf( "\n%.2f", value ); amount = value / 0.10; value = value - (amount * 0.10 ); if ( amount > 0 ) printf( "\n%.2f Dimes", amount ); printf( "\n%.2f", value ); amount = value / 0.01; value = value - (amount * 0.01 ); if ( amount > 0 ) printf( "\n%.2f Pennies", amount ); printf( "\n%.2f", value ); //amount = value / 0.1; printf( "%.2f", amount ); /* value = value - ( amount * 00.1 ); if ( amount > 0 ) printf( "\n%f Dimes", amount ); */ } /* end while */ //printf( "How much money do you give for payment?\n" ); //scanf( "%.2f\n", &userPayment); /* printf( "The amount you entered is less than you need to pay. Please try again.\n" ); scanf( "%3.2f\n", &userPayment); printf( "The total amount you need to pay is: "%d", &userPayment" ); (M1.pennies, M1.nickels, M1.dimes, M1.quarters, M1.dollars); */ return 0; /* indicates successful termination */ } /* end main */



LinkBack URL
About LinkBacks



