I have just run check50 and well the main part of my code is not working and I'm thinking it's because I'm not using the round function correctly. Please help.
Here's my code (ignore the constant printing of change owed and coins, I was trying to find out where I was going wrong!:
# include <stdio.h>
# include <cs50.h>
# include <math.h>
int main(void)
{
// Prompt user for amount owed and store this value
float dollars;
do
{
printf ("Hey, how much change is owed?\n");
dollars = GetFloat();
}
while (dollars <= 0);
// If acceptable value, convert from dollars to cents (x100) and round the value
float convert = dollars * 100;
float change = round(convert);
int cents = change;
int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;
int coins = 0;
int owed = 0;
// countdown from change owed to zero and count number of coins used
if (cents >= quarter)
{
owed = cents - quarter;
coins++;
printf("%d\n", owed);
printf("%d\n", coins);
}
else if (cents >= dime)
{
owed = cents - dime;
coins++;
printf("%d\n", owed);
printf("%d\n", coins);
}
else if (cents >= nickel)
{
owed = cents - nickel;
coins++;
printf("%d\n", owed);
printf("%d\n", coins);
}
else if(cents >= penny)
{
owed = cents - penny;
coins++;
printf("%d\n", owed);
printf("%d\n", coins);
}
// print number of coins used to screen
printf("%i\n", coins);
return 0;
}
And here are the results of check50:
~/workspace/pset1/ $ check50 2015.fall.pset1.greedy greedy.c
:) greedy.c exists
:) greedy.c compiles
:( input of 0.41 yields output of 4
\ expected output, but not "16\n1\n1\n"
:( input of 0.01 yields output of 1
\ expected output, but not "0\n1\n1\n"
:( input of 0.15 yields output of 2
\ expected output, but not "5\n1\n1\n"
:( input of 1.6 yields output of 7
\ expected output, but not "135\n1\n1\n"
:( input of 23 yields output of 92
\ expected output, but not "2275\n1\n1\n"
:( input of 4.2 yields output of 18
\ expected output, but not "395\n1\n1\n"
:) rejects a negative input like -.1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
Thank you in advance