get input from the keyboard and then print it

This commit is contained in:
Xavier Brinon
2024-02-12 15:15:29 +00:00
parent 1492157392
commit 15a215fab7
3 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,8 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
authors = ["HaQadosch Berraka <haqadosc+rusth@pm.me>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,14 @@
use std::io;
fn main() {
println!("Guess the number:");
println!("Please enter your guess");
let mut guess = String::new(); // Creates a mutable variable as empty string.
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
println!("You guessed: {guess}");
}