Created
July 12, 2016 21:26
-
-
Save dlecan/8db51c82946111f6df56de59d58c1aeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { | |
println!("Usage: division numerateur"); | |
return; | |
} | |
}; | |
let numerateur = match numerateur.parse() { | |
Ok(valeur) => valeur, | |
Err(_) => { | |
println!("Valeur non numérique de l'argument"); | |
return; | |
} | |
}; | |
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