The syntax you give (float roundf(float change_owed)
) is what would be used for declaring the function roundf
. That is, if you wanted to make a new function called roundf
. But it's already defined in math.h. You just want to use it. The syntax you'd use for what I think you meant to be doing would look more like this:
First, declare a float variable
float change_owed;
then, you get the input from user, and store it in that variable just made. Then, round it
float rounded = roundf(change_owed)
...
As for what roundf()
does precisely, type man roundf
in the terminal to see the man page for that function, where what it does is explained (yes, it does round to the nearest integer: 4.02375
, 4.123
, and 4.45
would all be rounded to the float 4.0
, but it's a good idea to actually read the man page, because you'll get all the information you need there).
In pset1, you want to round to an integer amount of cents. Say you're calling that int you get cents
. So, if you have a float
called dollars
, which you want to round to the nearest cent, that's rounding to two decimal places. Since the function roundf()
rounds to the nearest integer, not to two decimal places, in order to get the correct amount of cents
, you need to multiply dollars
by 100 before entering the dollar amount into the function. Then, since roundf()
outputs a float, you'll need to "cast" the result as an int
(know how to do that?).