The Challenge is:
- If the book is returned on or before the expected return date, no fine will be charged (i.e.: fine=0).
- If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, fine=15 Hackos × (the number of days late).
- If the book is returned after the expected return month but still within the same calendar year as the expected return date, the fine=500 Hackos × (the number of months late).
- If the book is returned after the calendar year in which it was expected, there is a fixed fine of 10000 Hackos.
And My code is:
<?php
$expectedDay = "6";
$expectedMonth = "6";
$expectedYear = "2015";
$returnDay = "9";
$returnMonth = "6";
$returnYear = "2015";
if ($expectedDay >= $returnDay && $expectedMonth >= $returnMonth && $expectedYear >= $returnYear) {
echo "Fine = 0";
}elseif ($expectedDay < $returnDay && $expectedMonth == $returnMonth && $expectedYear == $returnYear) {
$fine = 15 * ($returnDay-$expectedDay);
echo "Fine = ".$fine;
}elseif (($expectedDay <= $returnDay || $expectedDay >= $returnDay) && $expectedMonth < $returnMonth && $expectedYear == $returnYear) {
$fine = 500 * ($returnMonth-$expectedMonth);
echo "Fine = ".$fine;
}else{
echo "Fine = 1000";
}
?>
Its running well.But failed when the input is:
$expectedDay = "28";
$expectedMonth = "2";
$expectedYear = "2015";
$returnDay = "15";
$returnMonth = "4";
$returnYear = "2015";
How i write for this condition? Thanks in advanced.
Note: This is not a business logic.It is just Practice purposes.I am beginner in PHP.