Compare commits
No commits in common. "cb4c03abe969079dbdf14e8de032f9b70224812c" and "3edcc75e3ba10c951f765457da5f46131dd9b521" have entirely different histories.
cb4c03abe9
...
3edcc75e3b
23
src/main.rs
23
src/main.rs
|
@ -6,17 +6,18 @@ 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()
|
std::io::stdin().read_line(&mut input).expect("Failed to read line");
|
||||||
.read_line(&mut input)
|
let input: String = input.trim().parse().unwrap();
|
||||||
.expect("Failed to read line");
|
let yes:String = String::from("y");
|
||||||
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
|
let no = String::from("n");
|
||||||
match input { // Match is a better way then chaining if/else expressions.
|
if input == yes {
|
||||||
"y" => number += rng, // let expression would have shadowed the original variable and would have droped to soon. Use add assign insted
|
let number = number+=rng;
|
||||||
"n" => continue,
|
}
|
||||||
_ => {
|
else if input == no {
|
||||||
println!("Option unknown")
|
println!("maby the next number");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println!("Invalid input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue