Skip to content

Commit 167dd55

Browse files
committedAug 30, 2019
Add initial samples
0 parents  commit 167dd55

File tree

10 files changed

+164
-0
lines changed

10 files changed

+164
-0
lines changed
 

‎guessing-game/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

‎guessing-game/Cargo.lock

+91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎guessing-game/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "guessing-game"
3+
version = "0.1.0"
4+
authors = ["Chanaka Fernando <chanaka.leadership@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
rand = "0.3.14"

‎guessing-game/src/main.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::io;
2+
use std::cmp::Ordering;
3+
use rand::Rng;
4+
5+
fn main() {
6+
println!("Hello, world!");
7+
println!("Guess the number!");
8+
9+
let secret_number = rand::thread_rng().gen_range(1, 101);
10+
11+
loop {
12+
13+
println!("Please input your guess.");
14+
15+
let mut guess = String::new();
16+
io::stdin().read_line(&mut guess).
17+
expect("Failed to read line");
18+
19+
let guess: u32 = match guess.trim().parse() {
20+
Ok(num) => num,
21+
Err(_) => continue,
22+
};
23+
24+
25+
println!("You guessed this number: {}", guess);
26+
27+
match guess.cmp(&secret_number) {
28+
Ordering::Less => println!("Too small!"),
29+
Ordering::Greater => println!("Too big!"),
30+
Ordering::Equal => {
31+
println!("You win!");
32+
println!("The secret number is: {}", secret_number);
33+
break;
34+
}
35+
}
36+
}
37+
38+
}

‎hello-world/hello

207 KB
Binary file not shown.

‎hello-world/hello.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

‎hello_cargo/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

‎hello_cargo/Cargo.lock

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎hello_cargo/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "hello_cargo"
3+
version = "0.1.0"
4+
authors = ["Chanaka Fernando <chanaka.leadership@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

‎hello_cargo/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)