0

Ok so this is my improved code:

#include <stdio.h>
#include <cs50.h>        
#include <math.h>
int main (void)
{
float c;
int  a, n=0;

do
{
    c = get_float("Change: ");
}
while (c < 0);

//Round for each type of coin
c *=100;
a =round(c);
    //quarters
    while (a >= 25)
    {
        n++;
        a -= 25;
    }

    //dimes
    while (a >= 10)
    {
        n++;
        a -=25;
    }

    //nickels
    while (a >=5)
    {
        n++;
        a -= 25;
    }       

    //pennies
    while (a >=1)
    {
        n++;
        a -= 25;
    }


    //print coins
    printf("%i\n", n);
}

So it works for some values but doesn't work for others. Ex. if I input 0.41 it gives me 2 which is incorrect but if I input 65 it outputs 260 which is correct. Can someone help me on this issue? Thanks!

1 Answer 1

1

Cut and paste error. What is the value of a dime? A nickel? A penny? I'm sure it isn't 25 cents each!

;-)

When you get to the point that you're not seeing the forest for the trees, as is the case here, it's always best to take a break and set it aside for at least a couple hours, and not think about it at all. Better to let it sit overnight!

2
  • I’m so dumb. Wow. Thank you so much. I can’t even.... Wow. I have been stuck on this for like 5 days. Thanks so much. Commented Apr 22, 2019 at 23:16
  • You should really do something about that bruise on your forehead. You know, the one where you slapped your head or did a faceplant? ;-D Hey, we've all done stupid stuff like that at one point or another. Anyone that says they haven't is just lying to themselves! ;-)
    – Cliff B
    Commented Apr 22, 2019 at 23:24

You must log in to answer this question.

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