Created
November 5, 2015 15:03
-
-
Save pavarotti305/f14bf707f118084e7449 to your computer and use it in GitHub Desktop.
Random_Operation_Math
This file contains 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
<!DOCTYPE html> | |
<!-- | |
To change this license header, choose License Headers in Project Properties. | |
To change this template file, choose Tools | Templates | |
and open the template in the editor. | |
--> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>RandomCalcul</title> | |
</head> | |
<body> | |
<?php | |
// generation random number between 0 and 999 and the math operator | |
$nbr = 0; | |
$result = 0; | |
for ($i = 0; $i < 4; $i++) { | |
$nb = rand(0, 999); | |
$op = rand(0, 2); | |
switch ($op) { | |
case 0: | |
$op = '+'; | |
break; | |
case 1: | |
$op = '-'; | |
break; | |
case 2: | |
$op = '*'; | |
break; | |
} | |
if ($i != 3) { | |
echo $nb . ' ' . $op; | |
$result += $nb; | |
} else { | |
echo $nb; | |
$result += $nb; | |
} | |
} | |
echo '<br> The result is : '.$result; | |
?> | |
</body> | |
</html> |
rdoursenaud
commented
Nov 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment