-
-
Save rust-play/b54eb9601a5626ce3221b00b338dd3dc to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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