Table of content

What is this?

The rules of the game are explained in my original post.

9th Challenge

Challenge

Today’s challenge is converting celcius to fahrenheit, reading the input from the command-line. Its a challenge taken from Rust’s official documentation.

Solution

This is my solution:

	use std::io;

	fn main() {

	    let mut temp = String::new();

	    println!("enter °C value to be converted to Fahrenheit:");

	    io::stdin().read_line(& mut temp).expect("oops");

	    let temp:f32 = temp.trim().parse().expect("failed to parse");

	    println!("{}°C =  {} Fahrenheit",temp,celcius_to_fahrenheit(temp));

	}

	fn celcius_to_fahrenheit(celclius: f32) -> f32 {
	    celclius*1.8+32.0
	}
	

See github and playground