Log in

View Full Version : unexpected T_ELSE problem! please help



Legato213
10-12-2008, 06:57 PM
hello, im pretty new to php and i have to write a little program for my computer class but no matter what i do i get the error. help much appreciated the unexpected error is on like 14, 20, 26.


<?php

$loanamount = 0.0;
$deposit = 0.0;
$totalcost = 0.0;

printf("\nEnter Desired Loan Amount: ");
fscanf(STDIN, "%f", $loanamount);

if($loanamount > 0 && $loanamount < 25000 );
{
$deposit = $loanamount * .05;
}
else
{
if($loanamount >= 25000 && $loanamount < 50000 );
{
$deposit = ($loanamount - 25000) * .10;
}
else
{
if($loanamount >= 50000 && $loanamount <= 100000);
{
$deposit = ($loanamount - 50000) * .25;
}
else
{
if ($loanamount <= 0 || $loanamount > 100000);
{
printf("\n The amount requested is beyond the acceptable value. Please enter an amount between $0 and $100000");
}
}
}
}

printf("\nYour deposit will be %.2f",$deposit);
$totalcost = $loanamount + $deposit;
printf("\nYour total loan cost will be %.2f",$totalcost);
?>

dreamwave
10-12-2008, 07:09 PM
hi Legato213

you´r adding semicolon ';' after your IF statements.

TheJoshMan
10-12-2008, 07:20 PM
Try using this instead...




<?php

$loanamount = 0.0;
$deposit = 0.0;
$totalcost = 0.0;

printf("\nEnter Desired Loan Amount: ");
fscanf(STDIN, "%f", $loanamount);

if($loanamount > 0 && $loanamount < 25000 )
{
$deposit = $loanamount * .05;
}
else
{
if($loanamount >= 25000 && $loanamount < 50000 )
{
$deposit = ($loanamount - 25000) * .10;
}
else
{
if($loanamount >= 50000 && $loanamount <= 100000)
{
$deposit = ($loanamount - 50000) * .25;
}
else
{
if ($loanamount <= 0 || $loanamount > 100000)
{
printf("\n The amount requested is beyond the acceptable value. Please enter an amount between $0 and $100000");
}
}
}
}

printf("\nYour deposit will be %.2f",$deposit);
$totalcost = $loanamount + $deposit;
printf("\nYour total loan cost will be %.2f",$totalcost);
?>


Edit: Nevermind, the one above me beat me to the punch. LOL

Legato213
10-12-2008, 07:25 PM
lol thank you guys for you help! what a silly mistake

Twey
10-12-2008, 07:39 PM
Additionally, your code formatting is very weird. It becomes a lot more readable if you format it nicely and remove all the excess braces that are cluttering it up:
<?php
$loanamount = 0.0;
$deposit = 0.0;
$totalcost = 0.0;

printf("\nEnter Desired Loan Amount: ");
fscanf(STDIN, "%f", $loanamount);

if ($loanamount > 0 && $loanamount < 25000)
$deposit = $loanamount * .05;
else if ($loanamount >= 25000 && $loanamount < 50000)
$deposit = ($loanamount - 25000) * .10;
else if($loanamount >= 50000 && $loanamount <= 100000)
$deposit = ($loanamount - 50000) * .25;
else if ($loanamount <= 0 || $loanamount > 100000)
printf("\n The amount requested is beyond the acceptable value. Please enter an amount between $0 and $100000");

printf("\nYour deposit will be %.2f\n", $deposit);
$totalcost = $loanamount + $deposit;
printf("Your total loan cost will be %.2f\n", $totalcost);
?>