Cruz Castillo

Generation

generate functionFri, 05 May 2023

Bot program to count the products bought in the supermarket, with total sum.

fn main() { let mut sum = 0; for i in 0..5 { let mut input = String::new(); println!("Enter a number to add to the sum: "); std::io::stdin() .read_line(&mut input) .expect("Failed to read line"); let trimmed = input.trim(); match trimmed.parse::<u32>() { Ok(i) => sum += i, Err(..) => println!("this was not an integer: {}", trimmed), }; } println!("The sum is: {}", sum); }

Want to kickstart your project?Use the new AI Studio to create your code