#include <cs50.h>
#include <stdio.h>
int main(void)
{
float x;
int q1, d1, n1, p1, c, r1, r2, r3, t;
//prompt user for an amount of change
do
{
x = get_float("Please input the amount of change that is less than $1: ");
}
while ((x<0) || (x>1.0));
c = (int)(100 * x);
//always use the largest coin possible
//check if can use 25c coins
r1 = c % 25;
if ((c - r1) <0)
{
q1 = 0; // there is no quarter coin
}
else
{
q1 = (c - r1)/25; // there are q1 number of quarters
}
//check if can use 10c coins
r2 = r1 % 10;
if ((r1 - r2) <0)
{
d1 = 0; // there is no dime
}
else
{
d1 = (r1 - r2)/10; // there are d1 number of dimes
}
//check if can use 5c coins
r3 = r2 % 5;
if ((r2 - r3) <0)
{
n1 = 0; // there is no nickle
}
else
{
n1 = (r2 - r3)/5; // there are n1 number of nickle
}
//check if can use 1c coins
if ( r3 == 0)
{
p1 = 0; // there is no penny
}
else
{
p1 = r3; // there are p1 number of pennies
}
//keep track of coins
t = q1 + d1 + n1 + p1;
//print the final number of coins
printf("Total number of coins used: %i\n", t);
printf("Total number of quaters used: %i\n", q1);
printf("Total number of dimes used: %i\n", d1);
printf("Total number of nickles used: %i\n", n1);
printf("Total number of pennies used: %i\n", p1);
}