I am having a hard time with greedy. I think this first part is OK; I already checked it with check50. But in this second part I think I was kind of guessing. I put the first two lines just to show where money is coming from:

int money;
money = GetFloat();

int change = money*100;
int quarter, dime, nickel, penny;
int c1 = 0;
for (change =0; change >= 25; change--) 
    quarter = change - 25;

I made a similar loop for each kind of coin and wrote this to print out the result.


The only output I am getting from this sum is 0.

Can I make an int out of a float by multiplying it by 100?

Is the variable c1 updated each time the for loop runs?

2 Answers 2


To avoid problems, you can make it into a while loop. Also, assign values to your quarter, dime, nickel and penny.

int quarter=25,dime=10,nickel=5,penny=1;


//Other loops

//Print count
  • Great! I worked on those while loops and a problem of rounding the float money. pset1 solved. thanks.
    – msk
    Commented Jul 2, 2014 at 19:24
  • Glad I could help :)
    – kray
    Commented Jul 2, 2014 at 19:27

In your loop you're overwritting the variable change in it's declaration for (change =0; change >= 25; change--). First you tell that change = 0 so you are deleting your entry, also, each time the loop runs it should subtract 1 (change--) from the variable (apart to the 25 subtraction inside the loop... so it should subtract 26).

Even so, the loop declaration is also wrong, because you're asking for a countdown i-- while your loop has to run from 0 to 25).

By the way, money*100 can give you problems due the float imprecision, you should round that result.

You must log in to answer this question.

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