forked from Kiotolabs/structured-programming-lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3_task4.php
More file actions
63 lines (53 loc) · 1.73 KB
/
lab3_task4.php
File metadata and controls
63 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* ICS 2371 — Lab 3: Control Structures I
* Task 4: Nested Conditions — Loan Eligibility Checker [6 marks]
*
* IMPORTANT: You must complete pseudocode AND flowchart in your PDF
* report BEFORE writing any code below.
*
* @author [Kevin Mutua]
* @student [ENE212-0078/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [1 April 2026]
*/
/* Task 4 — HELB Loan Eligibility Checker */
// TEST DATA SETS (Update these to test A, B, C, D, and E)
$enrolled = true;
$gpa = 2.0;
$annual_income = 50000;
$previous_loan = true;
$final_status = "";
// 1. OUTER CHECK — Enrollment
if ($enrolled === true) {
// 2. INNER CHECK 1 — GPA
if ($gpa >= 2.0) {
// 3. INNER CHECK 2 — Income
if ($annual_income < 100000) {
$loan_amount = "Full loan";
} elseif ($annual_income < 250000) {
$loan_amount = "Partial 75%";
} elseif ($annual_income < 500000) {
$loan_amount = "Partial 50%";
} else {
$loan_amount = "Not eligible — Income above limit";
}
// 4. TERNARY — Renewal vs New (only if eligible for some loan)
// We check if the word "Not" is in the loan_amount string
if (strpos($loan_amount, "Not") === false) {
$app_type = ($previous_loan) ? "Renewal application" : "New application";
$final_status = "$loan_amount | $app_type";
} else {
$final_status = $loan_amount;
}
} else {
$final_status = "Not eligible — GPA below minimum";
}
} else {
$final_status = "Not eligible — must be an active student";
}
// 5. Output (SESE Principle)
echo "<h2>HELB Eligibility Result</h2>";
echo "Status: " . $final_status;
?>