From 020fb6271fee2d22e4beff516c941367b27eac3c Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Sun, 27 Feb 2022 20:37:43 -0800 Subject: [PATCH] bug fix didn't have a minimum accepted input size, and panicked during testing --- 02_Amazing/rust/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/02_Amazing/rust/src/main.rs b/02_Amazing/rust/src/main.rs index bc85189f..a1471a6a 100644 --- a/02_Amazing/rust/src/main.rs +++ b/02_Amazing/rust/src/main.rs @@ -163,12 +163,6 @@ fn main() { } println!("."); } - - - - - - } 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 match raw_input.trim().parse::() { - 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) => { println!("MEANINGLESS DIMENSION. TRY AGAIN. {}", e.to_string().to_uppercase()); continue; // run the loop again