mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
bug fix
didn't have a minimum accepted input size, and panicked during testing
This commit is contained in:
@@ -163,12 +163,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
println!(".");
|
println!(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_user_input(prompt: &str) -> usize {
|
fn get_user_input(prompt: &str) -> usize {
|
||||||
@@ -187,7 +181,15 @@ fn get_user_input(prompt: &str) -> usize {
|
|||||||
|
|
||||||
//from input, try to read a number
|
//from input, try to read a number
|
||||||
match raw_input.trim().parse::<usize>() {
|
match raw_input.trim().parse::<usize>() {
|
||||||
Ok(i) => break i, // this escapes the loop, returning i
|
Ok(i) => {
|
||||||
|
if i>1 { //min size 1
|
||||||
|
break i; // this escapes the loop, returning i
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println!("INPUT OUT OF RANGE. TRY AGAIN.");
|
||||||
|
continue;// run the loop again
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("MEANINGLESS DIMENSION. TRY AGAIN. {}", e.to_string().to_uppercase());
|
println!("MEANINGLESS DIMENSION. TRY AGAIN. {}", e.to_string().to_uppercase());
|
||||||
continue; // run the loop again
|
continue; // run the loop again
|
||||||
|
|||||||
Reference in New Issue
Block a user