The program is supposed to convert a entered dollar amount into dollars, half dollars, quarters, dimes, nickels, and pennies. I have some of the program but I can't figure out the exact math. PLEASE HELP!!!!
Here's code I have:
insert
Code:
include <stdio.h>
#include <math.h>
void convert(float amount);
void main(){
//Do not change this function
float amount;
printf("Enter the amount: $");
scanf("%f", &amount);
convert(amount);
}
void convert(float amount){
float dollar, hdollar,quarter, dime, nickel, penny;
double hd = 0.50, q = 0.25, d = 0.10, n = 0.05, p = 0.01;
dollar = amount / 1.00;
hdollar = (amount - (dollar * 1)); //% 50;
quarter = (amount - ((dollar * 1) - (hdollar * 50))); // % 25;
dime = (amount - ((dollar * 1) - (hdollar * 50) - (quarter * 25))); // % 10;
nickel = (amount - ((dollar * 1) - (hdollar * 50) - (quarter * 25) - (dime * 10))); // % 5;
penny = (amount - ((dollar * 1) - (hdollar * 50) - (quarter * 25) - (dime * 10) - (nickel * 5))); // % 1;
printf ("Dollar Bills: %lf\n", dollar);
printf ("hdollar: %lf\n", hdollar);
printf ("Half Dollars: %lf\n", fmod(hdollar,hd));
printf ("quarters: %lf\n", fmod(quarter,q));
printf ("Dimes: %lf\n", fmod(dime,d));
printf ("Nickle: %lf\n", fmod(nickel, n));
printf ("Pennies: %lf\n", fmod(penny,p));
}
Here's an example of what it's supposed to do:
Enter the amount: $7.73
Dollar bills: 7
Half dollars: 1
Quarters: 0
Dimes: 2
Nickels: 0
Pennies: 3