Skip to content
Snippets Groups Projects
Commit b47331fe authored by Joakim Lundberg's avatar Joakim Lundberg
Browse files

first entry

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 140 additions and 0 deletions
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-zircon"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "guessing_game"
version = "0.1.0"
dependencies = [
"rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159"
"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
"checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae"
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Joakim Lundberg <joakim@joakimlundberg.com>"]
[dependencies]
rand = "0.3"
\ No newline at end of file
extern crate rand;
// Librarys to include
use std::io;
use std::cmp::Ordering;
use rand::Rng;
// Main function
fn main()
{
let mut tries = 0;
let mut wins = 0;
let mut rng = gen_rng_num();
let mut stat = 0.0;
println!("Guess the number!"); // Prints a string
loop
{
if tries != 0 || wins != 0
{
stat = (wins as f32 / tries as f32) * 100.0;
}
println!("\n");
println!("{} Tries, {} Wins, {}%", tries, wins, stat);
println!("Please input you guess.");
let mut guess = String::new(); // creates a mutable variable
io::stdin().read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = guess.trim().parse()
.expect("Please type a number!");
println!("You guessed: {}", guess);
match guess.cmp(&rng)
{
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
rng = gen_rng_num();
println!("Changed secret number.");
wins = wins + 1;
}
}
tries = tries + 1;
}
}
fn gen_rng_num() -> u32
{
let random = rand::thread_rng().gen_range(1, 11);
random
}
\ No newline at end of file
ba2d367f992e7834
\ No newline at end of file
{"rustc":16691645817143570650,"features":"[]","target":16451677792840550653,"profile":731176819336294830,"deps":[["rand v0.3.17",8180839007690546724]],"local":[{"MtimeBased":[[1509465161,240026700],"/mnt/c/Users/Shawnshank/Desktop/Skola/D7018E - Rust/projects/guessing_game/target/debug/.fingerprint/guessing_game-4705d3f68048a38e/dep-bin-guessing_game-4705d3f68048a38e"]}],"rustflags":[]}
\ No newline at end of file
7d6c84ad7619868f
\ No newline at end of file
{"rustc":16691645817143570650,"features":"[]","target":16451677792840550653,"profile":731176819336294830,"deps":[],"local":[{"MtimeBased":[[1509461633,803249300],"/mnt/c/Users/Shawnshank/Desktop/Skola/D7018E - Rust/projects/guessing_game/target/debug/.fingerprint/guessing_game-9d515250f8fda0a0/dep-bin-guessing_game-9d515250f8fda0a0"]}],"rustflags":[]}
\ No newline at end of file
File added
7c2de9e233ba8b76
\ No newline at end of file
{"rustc":16691645817143570650,"features":"[\"default\", \"use_std\"]","target":7622704963989053380,"profile":731176819336294830,"deps":[],"local":[{"Precalculated":"0.2.33"}],"rustflags":[]}
\ No newline at end of file
File added
24de0dcabb2d8871
\ No newline at end of file
{"rustc":16691645817143570650,"features":"[]","target":4824587992598157425,"profile":731176819336294830,"deps":[["libc v0.2.33",8542125850251308412]],"local":[{"Precalculated":"0.3.17"}],"rustflags":[]}
\ No newline at end of file
File added
File added
/mnt/c/Users/Shawnshank/Desktop/Skola/D7018E - Rust/projects/guessing_game/target/debug/deps/guessing_game-9d515250f8fda0a0: src/main.rs
/mnt/c/Users/Shawnshank/Desktop/Skola/D7018E - Rust/projects/guessing_game/target/debug/deps/guessing_game-9d515250f8fda0a0.d: src/main.rs
src/main.rs:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment