function calculateSimpleInterest($principal, $rate, $years) {
// Validate inputs
if ($principal < 0 || $rate < 0 || $years < 0) {
return "Error: Principal, Rate, and Time must be non-negative values.";
}
// Calculate Simple Interest
$simpleInterest = ($principal * $rate * $years) / 100;
return $simpleInterest;
}
// Main Program
// Input values
$principal = 30000; // principal amount
$rate = 4; // annual interest rate in percentage
$years = 3; // time in years
// Calculate and display the result
$result = calculateSimpleInterest($principal, $rate, $years);
if (is_numeric($result)) {
echo "The Simple Interest for Principal = $principal, Rate = $rate%, and Time = $years years is: $result";
} else {
echo $result; // Display error message if inputs are invalid
}
/*
run:
The Simple Interest for Principal = 30000, Rate = 4%, and Time = 3 years is: 3600
*/