Puzzle 2 | Non-standard Input |
| use std::io::stdin; |
| |
| fn main() { |
| println!("What is 3+2? Type your answer and press enter."); |
| let mut input = String::new(); |
| stdin() |
| .read_line(&mut input) |
| .expect("Unable to read standard input"); |
| |
| if input == "5" { |
| println!("Correct!"); |
| } else { |
| println!("Incorrect!"); |
| } |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
The program’s interaction will look something like the following:
<= | What is ... |
Get Rust Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.