Skip to content

Instantly share code, notes, and snippets.

@dlecan
Last active December 10, 2016 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlecan/fce7cf1d7ee42daef21652440808377f to your computer and use it in GitHub Desktop.
Save dlecan/fce7cf1d7ee42daef21652440808377f to your computer and use it in GitHub Desktop.
use std::env;
fn calculer_division(x: i32, y: i32) -> i32 {
match y {
0 => panic!("Division par 0"),
1 => x,
_ => x / y
}
}
fn main() {
let numerateur = match env::args().nth(1) {
Some(argument) => argument,
None => panic!("Argument obligatoire manquant : le numérateur")
};
let numerateur = match numerateur.parse::<i32>() {
Ok(numerateur) => numerateur,
Err(error) => panic!("Impossible de convertir notre argument. Raison: {}", error)
};
let resultat = calculer_division(numerateur, 2);
println!("Résultat : {}", resultat);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment