-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfahr_cel.rs
60 lines (41 loc) · 1.24 KB
/
fahr_cel.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Celsius to Fehrenheit and Fehrenheit to Celsius.
use std::io;
fn main() {
println!("To convert Fehrenheit to Celsius press '1' and to do reverse press '2'");
let mut choice = String::new();
io::stdin()
.read_line(&mut choice)
.expect("Failed to read line");
let choice: u32 = choice
.trim()
.parse()
.expect("Please type a number.");
if choice == 1 {
println!("Enter the number: ");
let mut val = String::new();
io::stdin()
.read_line(&mut val)
.expect("Failed to read line");
let val: f32 = val
.trim()
.parse()
.expect("Please type a number.");
let mut c: f32 = val-32.0;
c = c*5.0;
c = c/9.0;
println!("Celsius to Fehrenheit : {c}.");
};
if choice == 2 {
println!("Enter the number: ");
let mut val = String::new();
io::stdin()
.read_line(&mut val)
.expect("Failed to read line");
let val: f32 = val
.trim()
.parse()
.expect("Please type a number.");
let f: f32 = ((val*9.0)/5.0) + 32.0;
println!("Celsius to Fehrenheit : {f}.");
};
}