TryBugHunt
cppType errorEasy

100 degrees Celsius converts to 132 Fahrenheit

BugFind the bug and fix the code

What it should do

toFahrenheit(celsius) converts a temperature with F = C * 9 / 5 + 32. Example: toFahrenheit(100) → 212

What happens instead

toFahrenheit(100) returns 132 instead of 212.

double toFahrenheit(double celsius) {
    return 9 / 5 * celsius + 32;
}

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the type errors pattern

Integer division, signed and unsigned mix-ups, and implicit conversions that change the value.

What you'll practise

An easy C++ debugging exercise about type errors: integer division, signed and unsigned mix-ups, and implicit conversions that change the value.

The checks your fix must pass

Signs of this kind of bug

Spoiler: why this bug happens(try it first; the hints get warmer one at a time)

What went wrong: The expression is worked out left to right, and 9 / 5 comes first. Both are int literals, so it is whole-number division and gives 1, not 1.8. The formula becomes celsius + 32.

The fix: Write one of them as a double, 9.0 / 5, or multiply first: celsius * 9 / 5.

Remember: A literal like 9 is an int and 9.0 is a double. A double later in the expression does not help a division that already happened.

The pattern behind it: type errors.

More type errors to practise

Embed this challenge on your site

Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.

<iframe src="https://trybughunt.com/embed/514ba593-cce2-4683-898e-ffa587a673a6" title="Debugging challenge: 100 degrees Celsius converts to 132 Fahrenheit" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/514ba593-cce2-4683-898e-ffa587a673a6">TryBugHunt</a></p>