1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*In this program, a function recieves a floating - point number entered by the user
that represents change from a purchase. The function will pass back the breakdown
of the change in dollar bills, half dollars, quarters, dimes, nickels, and pennies.
Written by: Joe
Date: 15 Nov 2011
*/
#include <stdio.h>
#include <stdlib.h>
float main (void)
{
// Local Def
float retChng;
int doll;
int hlf;
int qtr;
int dm;
int nic;
int pny;
// Statement
do
{
printf("Please enter a return change value less than $100.00: ");
scanf("%f", &retChng);
if (retChng > 99.99)
printf("\nThe value you entered is not below $100.00.\n");
}
while (retChng > 99.99);
printf("The value you entered is: %.2f\n\n", retChng);
printf("The change you will receive is:\n\n");
pny = retChng * 100;
doll = (pny / 100);
pny = (pny % 100);
hlf = (pny / 50);
pny = (pny % 50);
qtr = (pny / 25);
pny = (pny % 25);
dm = (pny / 10);
pny = (pny % 10);
nic = (pny / 5);
pny = (pny % 5);
printf("%d dollar bills\n", doll);
printf("%d half dollars\n", hlf);
printf("%d quarters\n", qtr);
printf("%d dimes\n", dm);
printf("%d nickels\n", nic);
printf("%d pennies\n", pny);
system("PAUSE");
return 1;
}//main
|