For the greedy.c program i am having a hard time getting started. I have seen the walkthrough, but i am still stuck.I don't want the answer i just want a hint! I have tried watching lots of other videos, but still nothing.


Start with this paragraph from the pset specs:

How few? Well, you tell us. Write, in a file called greedy.c in your ~/workspace/pset1 directory, a program that first asks the user how much change is owed and then spits out the minimum number of coins with which said change can be made. Use GetFloat from the CS50 Library to get the user’s input and printf from the Standard I/O library to output your answer. Assume that the only coins available are quarters (25¢), dimes (10¢), nickels (5¢), and pennies (1¢).

Think through some basic pseudocode now based only on this. You know you'll need to at least do the following:

// prompt the user for change using GetFloat
// perform some calculation (i.e. a greedy algorithm)
// return via printf the total number of coins

Later on in the specs, you will see about casting from float to int. Below Zamyla's walkthrough video, you also see sample output. You know you need to print O hai! How much change is owed? while the user's input is not a non-negative value.

Start incrementally. Maybe begin just with the prompt via printf. Then, prompt for input and figure out how to ensure the value entered by the user meets the requirements of the program. Then, cast it to an int. Finally, figure out the greedy algorithm itself.

See if this helps get you started.

You must log in to answer this question.

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