Skip to content

Commit

Permalink
rust basics
Browse files Browse the repository at this point in the history
  • Loading branch information
MahithChigurupati committed Jul 28, 2023
1 parent 61af9de commit bcf4e32
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 0 deletions.
Binary file added basics/main
Binary file not shown.
3 changes: 3 additions & 0 deletions basics/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(){
println!("Hello, world!")
}
1 change: 1 addition & 0 deletions basics_cargo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions basics_cargo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions basics_cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basics_cargo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions basics_cargo/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
1 change: 1 addition & 0 deletions guessing_game/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
228 changes: 228 additions & 0 deletions guessing_game/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions guessing_game/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[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"
colored = "2.0.0"
40 changes: 40 additions & 0 deletions guessing_game/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

use std::io;
use rand::Rng;
use std::cmp::Ordering;
use colored::*;

fn main() {
println!("****** Guessing Game ******");

let secret_number = rand::thread_rng().gen_range(1..101);

println!("The secret number is: {}", secret_number);


loop{
println!("Please enter your guess:");

let mut guess: String = 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!".red()),
Ordering::Greater => println!("{}", "Too big!".red()),
Ordering::Equal => {
println!("{}", "You win!".green());
break;
},
}
}
}
1 change: 1 addition & 0 deletions variables/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
8 changes: 8 additions & 0 deletions variables/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions variables/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit bcf4e32

Please sign in to comment.