0
 function isEqual($number1, $number2, $sum){

$total = $number1 + $number2;
    if ($total = $sum){
        return true;
    }
    else {
        return false;
    }
}

if (isEqual(5,5,8)){
echo 'Sum!';
}
else {
    echo 'No sum!';
    }

PHP

My homework assignment says the if-clause is supposed to be just like that. So when $total is NOT equal to $sum it's supposed to say: No sum!.

The thing is I shouldn't change the if, I have to change something in my function because it's always saying 'Sum!' right now.

Can someone help me with this? It's not supposed to be difficult but I can't find it on google.

3
  • 1
    Please, specify the programming language! Commented Oct 25, 2013 at 13:16
  • Aaaaaaand you deleted the code... Commented Oct 25, 2013 at 13:19
  • I've no idea what I am doing :P it 's solved by now thanks everybody! Commented Oct 25, 2013 at 13:20

3 Answers 3

5

Try $total == $sum instead of $total = $sum.

'=' is assignment and '==' is comparation

Sign up to request clarification or add additional context in comments.

Comments

1

You used $total = $sum instead of $total == $sum and therefore made an assignment rather than a comparison.

The value of an assignment expression is the value of the assigned value so it will always be true unless the assigned value is 0.

Comments

1

It appears that you're using the assignment operator ("=") in your conditional (if statement).

Try using the equality ("==", or double equals) operator to test for equality.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.