Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
zadanie2
<?php
function divide($divider, $dividend) {
if ($divider == 0){
throw new InvalidArgumentException("Divide by zero error");
}
if ($divider < 0){
throw new OutOfRangeException ("Divide is lover then zero");
}
return $dividend / $divider;
}
function randomDivide($tryNumber){
$invalidCounter = 0;
$outCounter = 0;
echo "---------------\n";
for ($n = 0; $n < $tryNumber; $n++){
try {
echo divide(rand(-10, 10), 5) . "\n";
} catch (InvalidArgumentException $e) {
$invalidCounter++;
} catch (OutOfRangeException $e) {
$outCounter++;
}
}
echo "---------------\n";
echo "| out: " . $outCounter . "\n";
echo "| inv: " . $invalidCounter . "\n";
echo "---------------\n";
}
randomDivide(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.