-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.rs
29 lines (22 loc) · 1.09 KB
/
main.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
// Create a simple menu-driven program using a loop and match statement.
use std::io;
fn main() {
let first: i32 = 42;
let second: i32 = 98;
println!("\nFirst number: {}, Second number: {} \n", first, second);
println!("Choose a operation to perform.");
println!("1. Addition\n2. Substraction\n3. Multiplication\n4. Division");
let mut operation: String = String::new();
println!("Enter the number that represnt the operation of your choice: ");
io::stdin()
.read_line(&mut operation)
.expect("Failed to read the user input!");
let operation: u8 = operation.trim().parse().expect("Enter a valid operation!");
match operation {
1 => println!("Addition of {} and {} is {}", first, second, first + second),
2 => println!("Substraction of {} from {} is {}", second, first, first - second),
3 => println!("Multiplication of {} wiht {} is {}", first, second, first * second),
4 => println!("Division of {} by {} is {}", first, second, first as f32 / second as f32),
_ => println!("Enter a valid operation!"),
}
}