summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guessing_game/Cargo.toml7
-rw-r--r--src/guessing_game/src/main.rs38
-rw-r--r--src/hello_cargo/Cargo.toml6
-rw-r--r--src/hello_cargo/src/main.rs3
-rw-r--r--src/hello_world/Cargo.toml6
-rw-r--r--src/hello_world/src/main.rs3
6 files changed, 63 insertions, 0 deletions
diff --git a/src/guessing_game/Cargo.toml b/src/guessing_game/Cargo.toml
new file mode 100644
index 0000000..15924f9
--- /dev/null
+++ b/src/guessing_game/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "guessing_game"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+rand = "0.10.1" \ No newline at end of file
diff --git a/src/guessing_game/src/main.rs b/src/guessing_game/src/main.rs
new file mode 100644
index 0000000..029eb36
--- /dev/null
+++ b/src/guessing_game/src/main.rs
@@ -0,0 +1,38 @@
+use std::io;
+use std::cmp::Ordering;
+
+use rand::prelude::*;
+
+fn main() {
+ println!("Guess the number!");
+
+ let secret_number = rand::rng().random_range(1..=100);
+
+ //println!("The secret number is: {secret_number}");
+
+ loop {
+ println!("Please input your guess.");
+
+ let mut guess = String::new();
+
+ io::stdin()
+ .read_line(&mut guess)
+ .expect("Failed to read line");
+
+ let guess: u32 = match guess.trim().parse() {
+ Ok(num) => num,
+ Err(_) => continue,
+ };
+
+ println!("You guessed: {guess}");
+
+ match guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
+ println!("You win!");
+ break;
+ }
+ }
+ }
+}
diff --git a/src/hello_cargo/Cargo.toml b/src/hello_cargo/Cargo.toml
new file mode 100644
index 0000000..f43e5f8
--- /dev/null
+++ b/src/hello_cargo/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello_cargo"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/hello_cargo/src/main.rs b/src/hello_cargo/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/hello_cargo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/hello_world/Cargo.toml b/src/hello_world/Cargo.toml
new file mode 100644
index 0000000..4f0a461
--- /dev/null
+++ b/src/hello_world/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello_world"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/hello_world/src/main.rs b/src/hello_world/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/hello_world/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}