Ok basically what I want to do is turn say $3.35 all in pennies whic will be 335. My problem is how do I stored a floating point value 3.335 like so into an int value so I can have 334 not 333.
here is my code I think it works sometimes but not all of them. what i think I did was copy the value of a float into an int to two values after the decimal point and then multiply it by 100. I noticed that some times will not match my float value by one cent.
I want the lines highlighted in red to alwasy print the same values. Thank you for your help.Code:float unitp = 1.25; float want; float totalamount; float payment; float change; int dchange; int newchange; printf("Welcome to crocop's meat market\n"); printf("the meat is priced at $1.25 each pound\n"); printf("How many pounds would you like to buy?\n"); scanf("%f", &want); totalamount=want * unitp; printf("the total you owe is $%.2f\n", totalamount); printf("How much do you want to make the payment for?\n"); scanf("%f", &payment); change = payment-totalamount ; printf("okay you will recive $%.2f in change\n", change); dchange=( 100* change+.5); printf("dchange = %d\n", dchange);



LinkBack URL
About LinkBacks



