php - Statement match there condition -
php - Statement match there condition -
i have question regarding condition. question : combined length of 2 sides of triangle must greater length of 3rd side segments form triangle. example, 8, 6 , 12 can form triangle because sum of 2 of 3 segments greater 3rd segment. however, 24, 5, , 15 cannot form triangle because sum of segments 5 , 15 not greater length of segment 24.
so, coding :
$aa = $_get['a']; $bb = $_get['b']; $cc = $_get['c']; if(($aa + $bb > $cc) || ($bb + $cc > $aa) || ($aa + $cc > $bb)){ echo"triangle"; } else{ echo"not triangle"; }
it can run, but, test number : 8, 6 , 12 , display triangle. number :24, 5, , 15 display triangle reply not triangle. can tell me why? tq
because all of these 3 conditions must met, not single one. replace
if(($aa + $bb > $cc) || ($bb + $cc > $aa) || ($aa + $cc > $bb)){
with
if(($aa + $bb > $cc) && ($bb + $cc > $aa) && ($aa + $cc > $bb)){
and should fine
php condition
Comments
Post a Comment