I am currently working on the pset1 greedy (cash) project. I am so close to finishing and I only have one more thing to complete before I can submit it as correct. I am working on rounding the initial cash amount up, but when I use round or roundf, I just get this error: implicitly declaring library function 'roundf' with type 'float (float)'

What could be wrong with my code? Here it is:

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

// Main Function
int main(void)

int cash;
float c = 100;
// Asks User for dollar amount
    printf("How much money do you have?\n");
    c = get_float();
    cash = roundf(c * 100);
while (c < 0);

// Total coin float
int coins = 0;

// Coin Values
cash = c * 100;
float quarter = 25;
float dime = 10;
float nickel = 5;
float penny = 1;

    // Quarters
    while (cash >= quarter) {
        cash = cash - quarter;
    // Dimes
    while (cash >= dime) {
        cash = cash - dime;
    // Nickels
    while (cash >= nickel) {
        cash = cash - nickel;

    // Pennies
    while (cash >= penny) {
        cash = cash - penny;
// Print how many coins there are
printf("%i\n", coins);

Thanks for the help and have a wonderful day!

1 Answer 1


Have you read the man page for the function? Maybe there's something your should include in your code that isn't there? ;-)

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

  • I did #include the other thing. It removed the error, but now I have two questions: the first one is - is it kind of cheating to use other headers or no? And also: even though the error is gone, for some reason 4.2 still returns 22 instead of 18. Where have I gone wrong? Jul 29, 2018 at 4:13
  • 1
    Using other header files is fine. It's how you make use of other libraries all the time. As for the 22 instead of 18, think about this. When a float is converted to an int, is it rounded or truncated? And what is the value stored in c, displayed to 15 digits? ;-)
    – Cliff B
    Jul 29, 2018 at 4:25
  • I know that it is usually truncated, and that is why it would ordinarily mess it up. However, I have used round on it, so why would it still truncate? Jul 29, 2018 at 12:41
  • 1
    This discussion has shifted off topic and requires seeing the current code. Please post a new question and we can go from there. In the meantime, if you feel the original question has been answered, please accept the answer so that this one closes out.
    – Cliff B
    Jul 29, 2018 at 19:53
  • It worked! The reason it still didn't work after you answered my question was because my variables were messed up. Thank you so much for the help and have a great day. Jul 29, 2018 at 19:59

You must log in to answer this question.

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