get input from the keyboard and then print it
This commit is contained in:
parent
1492157392
commit
15a215fab7
8
Projects/guessing_game/Cargo.toml
Normal file
8
Projects/guessing_game/Cargo.toml
Normal 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]
|
14
Projects/guessing_game/src/main.rs
Normal file
14
Projects/guessing_game/src/main.rs
Normal 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}");
|
||||
}
|
@ -31,7 +31,7 @@ To update *rustup* and please do regularly
|
||||
#+begin_src shell :results output
|
||||
rustup update
|
||||
#+end_src
|
||||
|
||||
(
|
||||
#+RESULTS: update rustup
|
||||
: stable-x86_64-unknown-linux-gnu unchanged - rustc 1.76.0 (07dca489a 2024-02-04)
|
||||
*** Documentation
|
||||
@ -183,3 +183,6 @@ To build a cargo with an optimised build, run
|
||||
#+end_example
|
||||
|
||||
The build results are in the folder =target/release/= now.
|
||||
|
||||
****
|
||||
* Programming a guessing game
|
||||
|
Loading…
Reference in New Issue
Block a user