0% found this document useful (0 votes)
6 views2 pages

PHP Lab 9 & 10

The document outlines a PHP lab exercise to create a checkout simulation for an online store. It includes generating a random purchase amount, applying discounts based on the total, simulating item addition with a while loop, displaying payment methods with a for loop, and processing payment using a switch statement. Key programming concepts covered include control structures, loops, and conditional statements.

Uploaded by

ankitgupta96466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

PHP Lab 9 & 10

The document outlines a PHP lab exercise to create a checkout simulation for an online store. It includes generating a random purchase amount, applying discounts based on the total, simulating item addition with a while loop, displaying payment methods with a for loop, and processing payment using a switch statement. Key programming concepts covered include control structures, loops, and conditional statements.

Uploaded by

ankitgupta96466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PHP Lab Exercise: Online Store Checkout Simulation

Objective:
Create a PHP script that simulates an online store checkout system using
control structures and loops.

Instructions:
Write a PHP script that performs the following tasks:

1. Generate a random total purchase amount between $500 and


$5000.

2. Apply a discount based on the total amount:

o Above $4000 → 20% discount

o Between $2500 and $4000 → 10% discount

o Below $2500 → No discount

3. Use a while loop to simulate the customer adding items to the cart
until the total reaches or exceeds the randomly generated amount.

4. Use a for loop to display the details of 5 different available


payment methods (e.g., Credit Card, PayPal, Bank Transfer, Apple
Pay, Google Pay).

5. Use a switch statement to process the payment method selected by


the user (hardcode a payment method selection).

6. Display the final total after applying the discount.

Expected Output Example:

Total purchase amount before discount: $4200

Applying a 20% discount...

Final amount to be paid: $3360

Available Payment Methods:

1. Credit Card

2. PayPal

3. Bank Transfer
4. Apple Pay

5. Google Pay

Selected Payment Method: Credit Card

Processing payment via Credit Card...

Payment Successful!

Key Concepts Covered:

 if-else statements for discount application

 Comparison operators for price evaluation

 while loop for item addition

 for loop for displaying payment methods

 elseif for multiple conditions

 switch statement for payment method processing

You might also like