From the course: Rust Essential Training

Unlock the full course today

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

Solution: Convert temperature

Solution: Convert temperature - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Solution: Convert temperature

(upbeat music) - [Instructor] To create my solution for the convert temperature challenge, I'll start by declaring a new function named Celsius to Fahrenheit. I need to give it an input parameter for the temperature in Celsius, and looking at line two, I see that the Celsius temp is declared as a floating point value, so I'll make the input parameter match that type. The return value should also be a floating point, so I'll add that to the function signature. Now, for the body of the function, I'll write an expression based on that equation to convert from Celsius to Fahrenheit. Temp times 1.8 plus 32. And that's it. To test out my solution, I'll use Cargo to build and run the program. Everything compiles fine, and when it runs, we get the message that the test passed. This challenge gave us practice writing a function in Rust with an input parameter and returning a result value.

Contents