Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 30, 2021 20:00
Show Gist options
  • Save rust-play/b54eb9601a5626ce3221b00b338dd3dc to your computer and use it in GitHub Desktop.
Save rust-play/b54eb9601a5626ce3221b00b338dd3dc to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
// https://pt.stackoverflow.com/q/525100/69296
use std::io;
fn main() {
println!("## Bem vindo ao conversor de Fahrenheit-2-Celcius! ##");
loop {
println!("Insira o valor em graus Fahrenheit ou 'quit' para sair:");
let mut fahrenheit = String::new();
io::stdin()
.read_line(&mut fahrenheit)
.expect("Deve ser um valor numérico ou 'quit' para sair.");
let fahrenheit = fahrenheit.trim();
if fahrenheit == "quit" {
println!("Saindo... até a próxima!");
break;
}
let fahrenheit: f64 = fahrenheit.trim().parse().expect("Digite um número válido.");
let celsius = (fahrenheit - 32.0) / 1.8;
println!("{} fahrenheit é/são {} em celsius.", fahrenheit, celsius);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment