C++20 sections · 1024 units
Open in Course

Temperature Convert - The Idea

Formula application

The trick is understanding how to translate a mathematical formula into code. The conversion formula F=C×95+32F = C \times \frac{9}{5} + 32 needs to be written exactly as shown, respecting operator precedence.

Multiplication and division happen before addition. I'll show you why data types matter. If you write 9/5 with integers, you get 1 instead of 1.8 because integer division truncates. You need at least one operand to be a double, so write 9.0/5 or 9/5.0.

You also need to format the output correctly. The problem asks for 2 decimal places, so you'll use fixed and setprecision from the iomanip library.