문제

I'm trying to figure out a way to convert celsius to fahrenheit using php. Here's my code so far. It keeps saying I have a unexpected '{' on line 12.

<html>
<body>
<?php
    for ($num=10, $num1=$num, $max=100; $num <= $max; $num++)
{
    if ((($num % 10) == 0))
{
    echo $num;
    echo ( " converted to fahrenheit is " );
}
    elseif ((5/9) * ($num1 - 32)
{
    echo $num1;
    echo ( "</br>" );
}
}
echo ( "</br> End Loop." );
?>
</body>
</html>

I'm a beginner. Just trying to get a grasp on php. Any help will be appreciated.

EDIT: It's supposed to convert every number divisble by 10 (e.g. 10, 20, 30, 40...) from Celsius to Fahrenheit.

도움이 되었습니까?

해결책

The specific error you're getting is because this:

elseif ((5/9) * ($num1 - 32)

Needs to be:

elseif ((5/9) * ($num1 - 32))

(Missing closing paren)

I think your entire script could be rewritten like this:

for ($num=10; $num <= 100; $num += 10) {
    $f = (($num * 9) / 5) + 32;
    echo "$num converted to fahrenheit is $f</br>";
}

Working example: http://3v4l.org/iT7p0

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top