A beginner C language question - do-while loop

Tell us what’s happening:

I am writing this C language program in CS50 lab, where I only need to accept positive dollar value. I wrote following program.

while Boolean expression should route it back to the loop whenever negative value is entered. but my program seems to take even negative value. Can’t understand why Boolean expression is not working. It seems to work if enter any word or alphanumeric characters.

Your code so far


// Prompt user for amount owed in dollar and cents
int get_positive_int(string prompt)
{
    float f;
    do
    {
        f = get_float("%s", prompt);
    }
    while (f < 0);
    return f;
}

I also tried following to circumvent this issue, still doesn't work

// Prompt user for amount owed in dollar and cents
int get_positive_int(string prompt)
{
    float f;
    int i;
    do
    {
        f = get_float("%s", prompt);
        i = f * 100;
    }
    while (i < 0);
    return f;
}

Your browser information:

I am using chrome.

Link to the challenge:
https://learn.freecodecamp.org/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements/