Exercise 6 · Chapter: Input & Type ConversionRequired+50 XP
Fix the Conversion
The code below is supposed to read a number, double it, and print the result. But it has bugs! Can you fix them?
Hints:
- Remember to trim the input before parsing.
- Make sure the variable is mutable.
- Check that you're parsing to the right type.
Expected output
10
rust
use std::io;
fn main() {
let input = String::new();
io::stdin().read_line(&input).unwrap();
let number: i32 = input.parse().unwrap();
println!("{}", number * 2);
}
Output
Run your code to see the output here.