Answers for "rust enter number from keyboard / stdin"

0

rust enter number from keyboard / stdin

use std::io;

// Request number
println!("Enter number? ");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let bint: i32 = input.trim()
  .parse()
  .ok()
  .expect("Program only processes numbers, Enter number");    
println!("Square {}", bint * bint); // use number
Posted by: Guest on March-12-2021

Browse Popular Code Answers by Language