-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessingGame.rs
More file actions
30 lines (28 loc) · 834 Bytes
/
guessingGame.rs
File metadata and controls
30 lines (28 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main(){
// Variables
let guessing_number:u8 = 10;
let mut hit_point:u8 = 3;
// Main Event loop
loop {
// Input buffer
let mut inputBuff = String::new();
if (hit_point == 0){
println!("Game over!");
println!("Better luck next time");
break;
}
println!("HP: {hit_point}");
println!("What is the number: ");
std::io::stdin().read_line(&mut inputBuff).expect("error");
let mut number:u8 = inputBuff.trim().parse().unwrap();
if (number == guessing_number){
println!("Correct!!!!");
println!("You Win!!!!!!!!!");
break;
} else {
println!("\tTry Again");
println!("--------------------------");
hit_point -= 1;
}
}
}