47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use std::io::{self, Write};
|
|
use std::process::exit;
|
|
|
|
use day30::max_value;
|
|
|
|
fn main() {
|
|
let mut buffer = String::new();
|
|
|
|
print!("Insert the starting number: ");
|
|
io::stdout().flush().expect("Failed to flush stdout");
|
|
|
|
io::stdin()
|
|
.read_line(&mut buffer)
|
|
.expect("Failed to read line");
|
|
|
|
let n: isize = match buffer.trim().parse() {
|
|
Ok(n) => n,
|
|
Err(_) => {
|
|
eprintln!("Invalid number");
|
|
exit(1);
|
|
}
|
|
};
|
|
|
|
buffer.clear();
|
|
|
|
print!("Insert the digit to add to the number: ");
|
|
io::stdout().flush().expect("Failed to flush stdout");
|
|
|
|
io::stdin()
|
|
.read_line(&mut buffer)
|
|
.expect("Failed to read line");
|
|
|
|
let digit: char = match buffer.trim().parse() {
|
|
Ok(digit) => digit,
|
|
Err(_) => {
|
|
eprintln!("Invalid digit");
|
|
exit(1);
|
|
}
|
|
};
|
|
|
|
let result = max_value(n, digit);
|
|
match result {
|
|
Ok(result) => println!("The maximum value possible is: {}", result),
|
|
Err(e) => eprintln!("Error: {}", e),
|
|
}
|
|
}
|