0
#include <cs50.h>
#include <stdio.h>
#include <math.h>

int main(void)
{

float n;

        //gets amount of change from user

do
{
    printf ("How much change is their?\n");

    n = GetFloat();
}
while (n<=0);

    //converts float to an int 1-100

float roundf(float n);

int j = n*100;

int c = 0;

while(j >= 25)
{
    c++;
    j = j - 25;
}

while(j >= 10)
{
    c++;
    j = j - 10;
}

while(j >= 5)
{
    c++;
    j = j - 5;
}

while(j >= 1)
{
    c++;
    j = j - 1;
}

printf("%d\n", c);

}

I passed all of the checks except ":( input of 4.2 yields output of 18 \ expected output, but not "22\n"" which is confusing because what it shows printed on my screen when I run 4.2 through my program is just "22" I don't see the \n. I've tried to take out the \n but then all of the checks fail. thanks for your time!

1

It's not the \n line feed. (I wish they'd fix that slightly misleading message.)

It's giving you an error because 22 is the wrong answer! 22 coins means 16 quarters, 1 dime, 1 nickel and 4 pennies. It should be 16 quarters and 2 dimes. Try printing out the contents of j right after it was created and initialized. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • 4.2 16 17 18 22 – kiki Jul 17 '16 at 4:58
  • Did you figure out why? – Cliff B Jul 17 '16 at 4:59
  • its still a little confusing that 4.2 reads it like that but .2 0 2 2 2 reads it like that – kiki Jul 17 '16 at 5:00
  • sorry i was having trouble with the new line function in this text editor – kiki Jul 17 '16 at 5:00
  • Check out the following link: cs50.stackexchange.com/questions/19096/… – Cliff B Jul 17 '16 at 5:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .