TryBugHunt
rustType errorEasy

Boiling point converts to 132 degrees

BugFind the bug and fix the code

What it should do

celsius_to_fahrenheit(c) converts a Celsius temperature to Fahrenheit using F = C × 9/5 + 32. Example: celsius_to_fahrenheit(100.0) → 212.0

What happens instead

celsius_to_fahrenheit(100.0) returns 132.0 instead of 212.0.

fn celsius_to_fahrenheit(c: f64) -> f64 {
    c * (9 / 5) as f64 + 32.0
}

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 overflow, truncating casts with as, and types that do not convert the way you expect.

What you'll practise

An easy Rust debugging exercise about type errors: integer overflow, truncating casts with as, and types that do not convert the way you expect.

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: 9 and 5 are integer literals, so 9 / 5 is integer division and equals 1. Casting that 1 to f64 gives 1.0, and the formula becomes c * 1.0 + 32.0. The fraction 1.8 is lost before the cast happens.

The fix: Use float literals so the division keeps its decimals: c * 9.0 / 5.0 + 32.0.

Remember: casting the result of an integer division is too late. Write 9.0 instead of 9 when you want decimal maths, or cast the numbers before dividing.

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/bc97fd5e-eb27-4f29-aff0-7ccabf957ee5" title="Debugging challenge: Boiling point converts to 132 degrees" 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/bc97fd5e-eb27-4f29-aff0-7ccabf957ee5">TryBugHunt</a></p>