From 53a2181a8096b020a58d45eae0000827e5891ac9 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sat, 25 Feb 2023 00:26:20 -0500 Subject: [PATCH] guessing game --- .gitignore | 3 ++ chapter1/.idea/.gitignore | 8 ---- chapter1/.idea/chapter1.iml | 11 ------ chapter1/.idea/modules.xml | 8 ---- chapter1/.idea/vcs.xml | 6 --- chapter1/tags | 6 --- guessing_game/Cargo.lock | 75 +++++++++++++++++++++++++++++++++++++ guessing_game/Cargo.toml | 9 +++++ guessing_game/src/main.rs | 21 +++++++++++ 9 files changed, 108 insertions(+), 39 deletions(-) create mode 100644 .gitignore delete mode 100644 chapter1/.idea/.gitignore delete mode 100644 chapter1/.idea/chapter1.iml delete mode 100644 chapter1/.idea/modules.xml delete mode 100644 chapter1/.idea/vcs.xml delete mode 100644 chapter1/tags create mode 100644 guessing_game/Cargo.lock create mode 100644 guessing_game/Cargo.toml create mode 100644 guessing_game/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ed99d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +tags +target diff --git a/chapter1/.idea/.gitignore b/chapter1/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/chapter1/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/chapter1/.idea/chapter1.iml b/chapter1/.idea/chapter1.iml deleted file mode 100644 index c254557..0000000 --- a/chapter1/.idea/chapter1.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/chapter1/.idea/modules.xml b/chapter1/.idea/modules.xml deleted file mode 100644 index daf6423..0000000 --- a/chapter1/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/chapter1/.idea/vcs.xml b/chapter1/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/chapter1/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/chapter1/tags b/chapter1/tags deleted file mode 100644 index bc069fd..0000000 --- a/chapter1/tags +++ /dev/null @@ -1,6 +0,0 @@ -!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ -!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ -!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ -!_TAG_PROGRAM_NAME Exuberant Ctags // -!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ -!_TAG_PROGRAM_VERSION Development // diff --git a/guessing_game/Cargo.lock b/guessing_game/Cargo.lock new file mode 100644 index 0000000..1d514e3 --- /dev/null +++ b/guessing_game/Cargo.lock @@ -0,0 +1,75 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "guessing_game" +version = "0.1.0" +dependencies = [ + "rand", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/guessing_game/Cargo.toml b/guessing_game/Cargo.toml new file mode 100644 index 0000000..5929822 --- /dev/null +++ b/guessing_game/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "guessing_game" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.8.5" \ No newline at end of file diff --git a/guessing_game/src/main.rs b/guessing_game/src/main.rs new file mode 100644 index 0000000..c367dd2 --- /dev/null +++ b/guessing_game/src/main.rs @@ -0,0 +1,21 @@ +use std::io; +use rand::Rng; + +fn main() { + println!("Guess the number!"); + + let secret_number = rand::thread_rng().gen_range(1..=100); + + println!("psst. the secret number is {secret_number}"); + + println!("Please input your guess."); + + let mut guess = String::new(); + + io::stdin() + .read_line(&mut guess) + .expect("Failed to read line"); + + println!("You guessed {guess}"); + +} \ No newline at end of file