Merge pull request 'Fix code.' (#2) from viridian/physik_test:main into main

Reviewed-on: #2
This commit is contained in:
robin 2024-05-10 13:53:56 +02:00
commit cb4c03abe9

View file

@ -6,18 +6,17 @@ fn main() {
println!("Do you want to add {} to the number", rng); println!("Do you want to add {} to the number", rng);
println!("Your number is {}(y/n)", number); println!("Your number is {}(y/n)", number);
let mut input: String = String::new(); let mut input: String = String::new();
std::io::stdin().read_line(&mut input).expect("Failed to read line"); std::io::stdin()
let input: String = input.trim().parse().unwrap(); .read_line(&mut input)
let yes:String = String::from("y"); .expect("Failed to read line");
let no = String::from("n"); 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
if input == yes { match input { // Match is a better way then chaining if/else expressions.
let number = number+=rng; "y" => number += rng, // let expression would have shadowed the original variable and would have droped to soon. Use add assign insted
} "n" => continue,
else if input == no { _ => {
println!("maby the next number"); println!("Option unknown")
}
else {
println!("Invalid input");
} }
} }
} }
}