If the user only presses Enter then the first character would be "\n".
yeah, you are right. Thanks for pointing out.
What version of Odoo was the best one?
Thank you for the in depth suggestion :)
Thanks, I will keep that in mind.
Thank you so much for the suggestion. I have updated the code locally :)
but to do that I have to use external deps? which I am not comfortable doing. (I am newbie :) )
Thank you for the suggestions.
attempts
is used to display total attempts when user wins the game so it is used in the program, I don't see any warnings from compiler.
done :D
use std::io;
fn main() {
let mut input: String = String::new();
let stdin = io::stdin();
let x = rand::random::<u32>() % 101;
let mut attempts = 0;
let mut user_inputs: Vec<u32> = Vec::new();
loop {
println!("Guess a number from 0 to 100:");
stdin.read_line(&mut input);
input = input.to_string().replace("\n", ""); // removing the \n
let user_input: u32 = input.parse::<u32>().unwrap();
user_inputs.push(user_input);
if x == user_input {
println!("You won! attempts: {attempts}");
println!("Your inputs:");
for input in user_inputs {
print!("{input} ");
}
println!("");
break;
}
else if x < user_input {
println!("too big");
attempts += 1;
}
else {
println!("too small");
attempts += 1;
}
input.clear()
}
}
Thank you for the suggestion, I will keep these in mind.
I am not much familiar with Rust that's why I am making these naive mistakes. Thank you for the suggestions though.