Софтуерно Инженерство
Loading...
tsvetinap avatar tsvetinap 1 Точки

Trade commissions - PHP

Здравейте,

не хващам какво пропускам, че да ми излиза програмата в judge след като в netbeans тръгва, моля помогнете frownsmiley Благодаря!

 

<?php

$city = strtolower(readline());
$sales = floatval(readline());
$commision = -1.0;


if ($city === "Sofia") {

    if ($sales >= 0 && $sales <= 500) {
        
    }
    $commision = ($sales * 0.05);
} else if ($sales > 500 && $sales <= 1000) {

    $commision = ($sales * 0.07);
} else if ($sales > 1000 && $sales <= 10000) {


    $commision = ($sales * 0.08);
} else if ($sales > 10000) {
 

    $commision = ($sales * 0.12);
}

else if ($city === "Varna") {
    
} else if ($sales >= 0 && $sales <= 500) {
    $commision = $sales * 0.045;
} else if ($sales > 500 && $sales <= 1000) {
    $commision = $sales * 0.075;
} else if ($sales > 1000 && $sales <= 10000) {
    $commision = $sales * 0.1;
} else if ($sales > 10000) {
    $commision =($sales * 0.13);

    
} else if ($city === "Plovdiv") {
    
} else if ($sales >= 0 && $sales <= 500) {
    $commision = ($sales * 0.055);
} else if ($sales > 500 && $sales <= 1000) {
    $commision = ($sales * 0.08);
} else if ($sales > 1000 && $sales <= 10000) {
    $commision = ($sales * 0.12);
} else if ($sales > 10000) {
    $commision = ($sales * 0.145);
    
}
if ($commision >= 0) {
    printf("%0.2f", $commision);
    
} else {
    echo "error" . PHP_EOL;
}

0
Programming Basics with PHP 29/03/2019 16:20:05
savchoo avatar savchoo 3 Точки

Здравей, ето ти действащ вариант: 

<?php

$city = readline();
$sales = floatval(readline());

$commision = 0;

$isCity = $city == 'Sofia' || $city == 'Varna' || $city == 'Plovdiv';

if ($city == 'Sofia') {
    if ($sales >= 0 && $sales <= 500) {
        $commision = $sales * (5 / 100);
    } else if ($sales > 500 && $sales <= 1000) {
        $commision = $sales * (7 / 100);
    } else if ($sales > 1000 && $sales <= 10000) {
        $commision = $sales * (8 / 100);
    } else if ($sales > 10000) {
        $commision = $sales * (12 / 100);
    }
} else if ($city == 'Varna') {
    if ($sales >= 0 && $sales <= 500) {
        $commision = $sales * (4.5 / 100);
    } else if ($sales > 500 && $sales <= 1000) {
        $commision = $sales * (7.5 / 100);
    } else if ($sales > 1000 && $sales <= 10000) {
        $commision = $sales * (10 / 100);
    } else if ($sales > 10000) {
        $commision = $sales * (13 / 100);
    }
} else if ($city == 'Plovdiv') {
    if ($sales >= 0 && $sales <= 500) {
        $commision = $sales * (5.5 / 100);
    } else if ($sales > 500 && $sales <= 1000) {
        $commision = $sales * (8 / 100);
    } else if ($sales > 1000 && $sales <= 10000) {
        $commision = $sales * (12 / 100);
    } else if ($sales > 10000) {
        $commision = $sales * (14.5 / 100);
    }
}

if ($isCity && $sales >= 0) {
    echo number_format($commision,2,".","");
} else {
    echo 'error';
}

0