# Activity 3

### Problem 1 Arthimetic Operation

##### A. Write a PHP script to calculate the area of the rectangle using arithmetic operations. Display the result.

#### Solution:

$length = 15;

$width = 10;

$area = length * width;

#### Output:

###### The area of the rectangle is 150

##### B. Implement a script that converts currecy from one denomination to another using arithmetic operators. Display the converted amount.

#### Solution:

$usd = 150;

$conversion_rate = 56.21;

$peso = $usd * $conversion_rate;

#### Output:

###### The converted amount is 8431.5

### Problem 2 Advanced Assignment Operators

##### A. Track the progress of the fundraising campaign by updating the donation total dynamically using combined assignment operators. Display the updated total.

#### Solution

$donation = 70,000;

$new_donation = 50,000;

$donation += $new_donation;

#### Outcome

###### The updated total donation is 120000

##### B. Implement a voting system where candidate votes are incremented based on user input. Display the final vote count for each candidate.

#### Solution:

$Candiate_one = 500;

user_vote = 1;

$voter_one += $user_vote;

#### Output

###### Candidate 1 total votes is 501

### Problem 3 Comparison Operators:

##### A. Compare the performance of two athletes in a race and determine the winner using comparison operators. Display the result.

#### Solution

$athlete_one = 30;

$athlete_two = 25;

if ($athlete_one > $athlete_two) {

echo "Athlete 1 is the winner";

} else {

echo "Athlete 2 is the winner";

}

#### Output

###### Athlete 1 is the winner.

##### B. Evaluate the efficiency of two algorithms based on their execution times using comparison operators. Display the more efficient algorithm.

#### Solution

$algorithm1 = 2.0;

$algorithm2 = 1.5;

if ($algorithm1 > $algorithm2) {

echo "Algorithm 1 is more efficient than algorithm 2.";

} else {

echo "Algorithm 2 is more efficient than algorithm 1.";

}

#### Output

###### Algorithm 2 is more efficient than algorithm 1.

## Problem 4 Increment/Decrement Operations

##

##### A.Calculate the factorial of a number using postfix increment/decrement operations. Display the factorial

#### Solution

$num = 4;

$factorial = $num1;

for ($i = $num - 1; $i > 0; $i; $i--) {

result *= $i

}

echo "The factorial of $num is $factorial"

#### Output

###### The factorial of 4 is 24.

##### Simulate the movement of a vehicle along a track using prefix increment/decrement operations. Display the final position of the vehicle

#### Solution

$first_position = 0;

$final_position = 15;

$first_position += $final_position;

echo "The final position of the vehicle is $final_position."

#### Output

The final position of the vehicle is 15.

## Probelm 5 Logical Operators:

##### A. Determine eligibility for a discount based on purchase amount and customer loyalty using logical operators. Display whether the customer is eligible for a discount.

#### Solution

$puchase_amount = 50000;

$avail_loyalty = true;

if ($purchase_amount > 0 && $avail_loyalty > 0) {

echo "Customer is eligible for a discount";

} else {

echo "Customer is not eligible for a discount";

}

#### Output

###### Customer is eligible for a discount

##### B. Design a decision-making system for a chatbot to respond to user queries using logical operators Display the appropriate response based on the query.

#### Solution

$user_query = "month";

if (!($user_query == month)) {

echo "February";

} else {

echo "I can't remember!";

}

#### Output

###### February