This is the output of my tests:
:) greedy exists
:) greedy compiles
:( input of 0.41 yields output of 4
expected "4\n", not "3\n"
:( input of 0.01 yields output of 1
expected "1\n", not "0\n"
:) input of 0.15 yields output of 2
:) input of 1.6 yields output of 7
:) input of 23 yields output of 92
:) input of 4.2 yields output of 18
:) rejects a negative input like -.1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
This is the code:
#include <stdio.h>
#include <cs50.h>
void count_coins();
int coin = 0;
float change = 0;
int main(void)
{
do
{
change = get_float("How much change is owed? ");
}
while (change < 0);
count_coins();
printf("%i\n", coin);
}
void count_coins()
{
while (change > 0.24)
{
coin++;
change -= 0.25;
// printf("%.2f\n", change);
}
while (change > 0.09)
{
coin++;
change -= 0.10;
// printf("%.2f\n", change);
}
while(change > 0.04)
{
coin++;
change -= 0.05;
// printf("%.2f\n", change);
}
while (change >= 0.01)
{
coin++;
change -= 0.01;
// printf("%.2f\n", change);
}
}