echo libraryFine_3(10, 7, 2015, 7, 7, 2015)."\n\n";
echo libraryFine_3(10, 8, 2015, 5, 3, 2015)."\n\n";
echo libraryFine_3(10, 7, 2017, 5, 7, 2015)."\n\n";
echo libraryFine_3(10, 7, 2017, 10, 7, 2017)."\n\n";

//Using if and else if functions
function libraryFine($d1, $m1, $y1, $d2, $m2, $y2) {
	$hacks = 0; //fine unit hackos
	$a = $d1-$d2;
	$b = $m1-$m2;
	$c = $y1-$y2;

	if ($a == 0 && $b == 0 && $c == 0) {
		$hacks = 0;
	} else {
		if ($a != 0) {
			$hacks = 15*$a;
		}if ($b != 0) {
			$hacks = 500*$b;
		}if ($c != 0) {
			$hacks = 10000;
		}
		return $hacks;
	}
}  //This is my idea, maybe good, maybe not so


//Using switch function
function libraryFine_2($d1, $m1, $y1, $d2, $m2, $y2) {
	$hacks = 0;
	$a = $d1-$d2;
	$b = $m1-$m2;
	$c = $y1-$y2;

	switch ($hacks) {
		case ($a == 0 && $b == 0 && $c == 0):
			$hacks = 0;
			break;
		case ($a != 0):
			$hacks = 15*$a;
			break;
		case ($b != 0):
			$hacks = 500*$b;
			break;
		case ($c != 0):
			$hacks = 10000;
			break;
	}
	return $hacks;
}  // doesn't work

// Calculates the fine, if the book is returned late
function libraryFine_3($d1, $m1, $y1, $d2, $m2, $y2) {
    
    $hacks = 0;
    
    // If the book is returned after the calendar 
    // year, there is a fixed fine of 10,000 Hackos
    if ($y1 > $y2) {
        $hacks = 10000;
    } 
    
    // If the book is returned after the expected return 
    // month but still within the same calendar year
    else if ($m1 > $m2  &&  $y1 == $y2) {
        $hacks = 500 * ($m1 - $m2);
    }
    
    // If the book is returned after the expected return 
    // day but still within the same calendar month and year
    else if ($d1 > $d2  &&  $m1 == $m2  &&  $y1 == $y2) {
        $hacks = 15 * ($d1 - $d2);
    }
    return $hacks;
} //fastets solution
by ვაჟა ტყემალაძე
1 year ago
PHP
Problem Solving
php
Note
Problem
0
Pro tip: use ```triple backticks around text``` to write in code fences