-
-
Save erickt/3849250 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use io::ReaderUtil; | |
fn main() { | |
io::println("What is your favorite number?"); | |
fn read_favorite_number() -> int { | |
for io::stdin().each_line |line| { | |
match int::from_str(line) { | |
None => { io::println("That is not a number. :(\nTry again!"); } | |
Some(number) => { return number; } | |
} | |
} | |
fail ~"I just wanted a number..."; | |
} | |
let my_favorite_number = read_favorite_number(); | |
io::println(fmt!("What? %d? That's my favorite too!", my_favorite_number)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment