When I run the program , It has no error, but when I run it, it gives result that I don't want
The Program(Rust):
use std::io;
fn main() {
println!("What temperature do you want to convert to?");
println!("Celcius to Fahrenheit?,Please Type cf");
println!("Fahrenheit to Celcius?,Please Type fc");
let mut the_answer = String::new();
io::stdin().read_line(&mut the_answer).expect("The Answer");
let x = String::from(the_answer);
println!("You want to convert to : {}", x);
println!("What temperature would you like to convert?");
let mut temperature = String::new();
io::stdin().read_line(&mut temperature).expect("The Number");
let temperature : i32 = match temperature.trim().parse(){
Ok(temperature) => temperature,
Err(_e) => {
-1
}
};
match x.as_str(){
"cf\n" => println!("{}", cf(temperature)),
"fc\n" => println!("{}", fc(temperature)),
_ => println!("temperature = {:?}", x),
}
}
fn cf(c: i32) -> i32 {
(c * (9/5)) + 32
}
fn fc(f: i32) -> i32 {
(f-32)*(5/9)
}
The Result:
Compiling Converter v0.1.0 (C:\Users\NicMar\Documents\Rust Projects\Converter)
warning: crate `Converter` should have a snake case name
|
= note: `#[warn(non_snake_case)]` on by default
= help: convert the identifier to snake case: `converter`
warning: `Converter` (bin "Converter") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.32s
Running `target\debug\Converter.exe`
What temperature do you want to convert to?
Celcius to Fahrenheit?,Please Type cf
Fahrenheit to Celcius?,Please Type fc
cf
You want to convert to : cf
What temperature would you like to convert?
12
temperature = "cf\r\n"
the result is supposed to be temperature =53.6,
but it shows temperature = "cf\r\n"
Is there any mistake about my code? or I should change the version of the rust?