什么是我的逻辑?

时间:2013-10-29 20:25:22

标签: php math

我把这个简单的逻辑放在一起添加两个数字,回显a和b的值,然后显示答案,这里已经很晚了,但我不明白为什么答案不是$ a + $ b的总和。我认为这是ABC的东西,但有点帮助不会错过。提前谢谢。

$number_one = mt_rand(1,100);
$number_two = mt_rand(1,100);

function add_numbers($a, $b) 
{
$sum = $a + $b; 
return $sum;
}

echo "What is " . $number_two . " + " . $number_two . "? <br />";
$answer = add_numbers($number_one, $number_two);
echo $answer;

1 个答案:

答案 0 :(得分:3)

因为你有一个错字......

echo "What is " . $number_two . " + " . $number_two . "? <br />";

应该是:

echo "What is " . $number_one . " + " . $number_two . "? <br />";
                          ^^^