You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Read byte only gets you a single byte (i.e the first ascii character you type in), so gives you a number. You need read_line, which is in ReaderUtil, which Reader can be cast to (I think this is the right way to do it).
After that, you can try to convert the string into an int. Someone might put something other than an int in, though, and to stop everything blowing up, Rust instead returns an option instead - which means it might be there, or might not be. So, you check it with 'is_some', to make sure it's really there, and then can unwrap it to get the juicy, juicy number.
fnmain(){//First, we read the input linelet my_number_string = (io::stdin()as io::ReaderUtil).read_line();
io::println(my_number_string);//Then, we try to turn it into an intlet maybe_my_int = int::from_str(my_number_string);if(option::is_some(maybe_my_int)){match option::unwrap(maybe_my_int){0 => io::println("zero"),1|2 => io::println("one or two"),3..10 => io::println("three to ten"),
_ => io::println("something else")}}else{
io::println("Not a number!");}}
How can I read pure decimal?
Please Let me know it .
I attach source below.
OUTPUT
1
49
something else
The text was updated successfully, but these errors were encountered: