From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,300 courses taught by industry experts.

Solution: Do some math

Solution: Do some math

(upbeat music) - [Instructor] Let me code a solution. Variables A and C can be integers because the math operations don't involve divisions. (keys tapping) Variable B however, must be a float because it's used in division. (keys tapping continues) In the challenge source code file, I set a hint here in the second print F statement where you see this, the percent F placeholder. This indicates a floating point value, and I hope you picked up on this hint. Next come the variable assignments and all the math as outlined in the challenge. (keys tapping) A is assigned the value 15 (keys tapping continues) B is assigned the value of variable A divided by 2, and I've used floating point notation for the literal here 0.0. The 0.0 causes the compiler to interpret the value as a real number, (keys tapping) and variable C is assigned the value of variable B multiplied by 4, which again can be an integer. I'll run my solution. And the proper output shows A is 15, B is 7.5, and C is 30. If you…

Contents