Created
September 20, 2012 11:56
-
-
Save ryuichimatsumoto-single/3755486 to your computer and use it in GitHub Desktop.
calculate?
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
<?php | |
/* | |
*問題用の配列 | |
* | |
*/ | |
$question = array | |
( | |
1 => array ("value1" => 10,"value2" => 22, "plus" => 1), | |
2 => array ("value1" => 2,"value2" => 4, "plus" => 2), | |
3 => array ("value1" => 2,"value2" => 198, "plus" => 3), | |
4 => array ("value1" => 20,"value2" => 20, "plus" => 4), | |
); | |
function fugou($plus) | |
{ | |
if($plus == 1) | |
{ | |
return "+"; | |
}else if($plus == 2){ | |
return "-"; | |
}else if($plus == 3){ | |
return "*"; | |
}else if($plus == 4){ | |
return "/"; | |
}else{ | |
//ミス入力対策 | |
return "?"; | |
} | |
} | |
function calculate($value1,$value2,$plus) | |
{ | |
if($plus == 1) | |
{ | |
return ($value1 + $value2); | |
}else if($plus == 2){ | |
return ($value1 - $value2); | |
}else if($plus == 3){ | |
return ($value1 * $value2); | |
}else if($plus == 4){ | |
return ($value1 / $value2); | |
}else{ | |
//ミス入力対策 | |
return ($value1 + 2 * $value2); | |
} | |
} | |
function check($question,$answer) | |
{ | |
$compare = calculate($question['value1'],$question['value2'],$question['plus']); | |
if($compare == $answer) | |
{ | |
return "OK"; | |
}else{ | |
return "NG"; | |
} | |
} | |
?> | |
<html> | |
<?php if(isset($_GET['answer_no'])){ echo check($question[$_GET['answer_no']],$_GET['answer']);} ?> | |
<?php echo $question[$_GET['no']]['value1']; ?><?php echo fugou($question[$_GET['no']]['plus']); ?><?php echo $question[$_GET['no']]['value2']; ?>= | |
<p>please input answer.</p> | |
<form action="answer.php" method="get"> | |
<input type="number" name="answer"> | |
<input type="hidden" name="no" value="<?php echo $_GET['no']+1;?>"> | |
<input type="hidden" name="answer_no" value="<?php echo $_GET['no'];?>"> | |
<input type="submit" value="final_answer"> | |
</form> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment