tempertature_convertion
This commit is contained in:
parent
eea33ef309
commit
2b4f9bc2ad
2 changed files with 60 additions and 0 deletions
8
7-temperature_convertion/Cargo.toml
Normal file
8
7-temperature_convertion/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "temperature_convertion"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
52
7-temperature_convertion/src/main.rs
Normal file
52
7-temperature_convertion/src/main.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
use std::io;
|
||||||
|
fn get_input() -> u32
|
||||||
|
{
|
||||||
|
loop
|
||||||
|
{
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut input)
|
||||||
|
.expect("Failed to read line");
|
||||||
|
match input.trim().parse()
|
||||||
|
{
|
||||||
|
Ok(num) => return num,
|
||||||
|
Err(_) =>
|
||||||
|
{
|
||||||
|
println!("Expected Valid Number");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
println!("Hello, world!");
|
||||||
|
|
||||||
|
println!("1) Fahrenheit to Celsius\n2) Celsius to Fahrenheit");
|
||||||
|
let mut selection;
|
||||||
|
let mut b = true;
|
||||||
|
while b
|
||||||
|
{
|
||||||
|
selection = get_input();
|
||||||
|
match selection
|
||||||
|
{
|
||||||
|
1 =>
|
||||||
|
{
|
||||||
|
println!("Fahrenheit Value = ↓");
|
||||||
|
selection = get_input();
|
||||||
|
println!("Celsius Value = {}", (selection-32) as f32*5.0/9.0);
|
||||||
|
b = false;
|
||||||
|
},
|
||||||
|
2 =>
|
||||||
|
{
|
||||||
|
println!("Celsius Value = ↓");
|
||||||
|
selection = get_input();
|
||||||
|
println!("Fahrenheit Value = {}", (selection as f32*9.0/5.0)+32.0);
|
||||||
|
b = false;
|
||||||
|
},
|
||||||
|
_ =>
|
||||||
|
{
|
||||||
|
println!("Expected Valid Value");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue