Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why is my code faulty? Ive tried everything in my reach
So, i am new to rust, and i thought it would be a fun project to make a minutes to seconds converter inputted by the user. But, i soon found out that you CANNOT multiply a string by an integer, so please i need help, im also trash at programming in general so, im sorry if the answer is too obvious
fn main() {
let mut input = String::new();
const SECONDS_IN_MINUTE: i32 = 60;
println!("{}",SECONDS_IN_MINUTE);
let MINUTE_IN_SECONDS: i32 = SECONDS_IN_MINUTE * input;
println!("how many minutes do you want to convert?");
io::stdin()
.read_line(&mut input)
.expect("FAIL! FAIL! FAIL!");
// chat gpt im gonna throw a sandal at you if this doesnt work
let input: i32 = input.trim().parse().expect("Please enter a valid number");
let MINUTE_IN_SECONDS: i32 = SECONDS_IN_MINUTE * input;
println!("Your result is: {}!", input);
}
1 post - 1 participant
🏷️ Rust_feed