physik_test/src/main.rs
2024-05-10 13:50:00 +02:00

23 lines
916 B
Rust

use rand::Rng;
fn main() {
let mut number: i128 = 0;
loop {
let rng: i128 = rand::thread_rng().gen_range(1..=1000000000000000000000000);
println!("Do you want to add {} to the number", rng);
println!("Your number is {}(y/n)", number);
let mut input: String = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let input = input.trim(); // Parse is for numbers we use letters here. A &str is more usefull in this case as we dont want to mutate it
match input { // Match is a better way then chaining if/else expressions.
"y" => number += rng, // let expression would have shadowed the original variable and would have droped to soon. Use add assign insted
"n" => continue,
_ => {
println!("Option unknown")
}
}
}
}