From the course: C Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Rounding and truncating example

Rounding and truncating example - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

Rounding and truncating example

- In this example I want to do something a little different. So, I will not be typing in so much code, but rather I will fill in some very particular parts of the code that require the functions that we just saw. So if you take a look at line five, you will see that we have two double variables, hours and age, because I am using the same example of hours in a parking lot and the age of a person. Hours is 3.1 and age is 14.8. So let's take a look at line seven. It says I parked for this many hours, so I got this many hours charged. So, we are using the hours variable and we have to use some function that will approximate that value to what the parking lot will charge. Remember, this parking lot charges per hour, so if I exceed one hour by one second, I will get charged for the whole hour. So, in this part, the last argument of this printer function call will have to be the ceiling of hours. So, I will type in ceil of hours. Why? Because the ceiling is the next integer not less than the…

Contents