0

In the Cash assignment, I am trying to print my variable cents to ensure it is properly stored. Why doesn't my code accomplish this? There is no output beyond the do while loop. Additionally, in this line int cents = (int)roundf(dollars*100);, why must int be specified twice? Would int cents = roundf(dollars*100); be incorrect? Why?

#include <math.h>

int main(void)
{
    float dollars;
    do
    {
        dollars = get_float("Change owed: ");
    }
    while (dollars<0);
    return dollars;
    
    int cents = (int)roundf(dollars*100);
    printf("%d/n", cents);

}
2

When you say return dollars, your program gives an output = "dollars" and ends itself. The line of code after returning dollars is not even read. Just remove the return statement and try your code. Have a great day.. :)

| improve this answer | |

You must log in to answer this question.

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