I've tried using the method here to read command line arguments as strings and the method here to convert strings to integers. However, when I run the code using "cargo run 1 2 3" instead of getting 6 as an output I get an error saying
thread 'main' panicked at 'called
Result::unwrap()
on anErr
value: ParseIntError { kind: InvalidDigit }', src/main.rs:7:45
I don't know what I'm doing wrong here. As far as I'm concerned I did essentially the same thing as the answers marked correct in the two threads I linked above.
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
let first: i32 = args[0].parse::<i32>().unwrap();
let second: i32 = args[1].parse::<i32>().unwrap();
let third: i32 = args[2].parse::<i32>().unwrap();
let result: i32 = first * second * third;
println!("The product of your three arguments is {result}.");
}