wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Product Discount Calculator

profile
Vaishnavi Nayak
Sep 07, 2025
0 Likes
0 Discussions
5 Reads

The program performs the following key functions:

Takes user input for three product prices, each greater than 0.

Validates that the entered prices are numbers and greater than zero.

Calculates the total bill amount by summing the three product prices.

Applies a discount of 10% on the total amount.

Calculates the final payable amount after discount.


Displays the results:

Price of each product

Total amount before discount

Discount applied

Final payable amount (formatted to 2 decimal places)


Program:


;; Product Discount Calculator


(defun calculate-discount (average total)

"Return discount rate and final amount after discount."

(let ((discount-rate

(cond ((>= average 1000) 0.20)

((>= average 500) 0.10)

((>= average 100) 0.05)

(t 0.0))))

(values discount-rate (* total (- 1 discount-rate)))))


(defun get-valid-price (prompt)

"Ask user for a valid product price (number > 0)."

(format t "~%~A (Enter price > 0): " prompt)

(let ((price (read)))

(if (and (numberp price) (> price 0))

price

(progn

(format t "Invalid price! Please enter a number greater than 0.~%")

(get-valid-price prompt)))))


(defun main ()

(format t "~%Welcome to Product Discount Calculator~%")


;; Get three product prices

(let* ((p1 (get-valid-price "Enter price of Product 1"))

(p2 (get-valid-price "Enter price of Product 2"))

(p3 (get-valid-price "Enter price of Product 3"))

(total (+ p1 p2 p3))

(average (/ total 3.0)))


;; Properly bind discount-rate and final-amount

(multiple-value-bind (discount-rate final-amount)

(calculate-discount average total)


;; Display results

(format t "~%Results:~%")

(format t "Product 1 Price: ~,2F~%" p1)

(format t "Product 2 Price: ~,2F~%" p2)

(format t "Product 3 Price: ~,2F~%" p3)

(format t "Total Price: ~,2F~%" total)

(format t "Average Price: ~,2F~%" average)

(format t "Discount Applied: ~,2F%%~%" (* discount-rate 100))

(format t "Final Payable Amount: ~,2F~%" final-amount))))


;; Run the program

(main)


Output:


Comments ()


Sign in

Read Next

E-commerce

Blog banner

Multithreading in Operating System

Blog banner

Hacking of web server and application

Blog banner

Craziness of dream 11 and how it impacts on our life

Blog banner

RAID_142

Blog banner

Precision-Recall in Data Science

Blog banner

Memory Management

Blog banner

MD5 Collisions and the impact on computer forensics

Blog banner

Why Your Daily Meal Routine Matters More Than Occasional Healthy Eating

Blog banner

Linux 94

Blog banner

E-BUSINESS RISK MANAGEMENT

Blog banner

Wedding photographer

Blog banner

Apache Kafka

Blog banner

Life of an army person

Blog banner

Modern Teaching Methods: Why Inquiry-based & Experiential Learning Works Best

Blog banner

Cyber-crime Investigation and Future Directions

Blog banner

Stay Close To Adventure In Arcadia, Florida At Oak Tree Hotel

Blog banner

Network Forensics Tools and Techniques

Blog banner

CRISP-DM Methodology

Blog banner

SAVE TREES

Blog banner

Why Businesses Are Investing More in Automation than Advertising?

Blog banner

VIRUS

Blog banner

Senseless Teeths

Blog banner

Monday. com App

Blog banner

Smart Eating Habits for Office Professionals to Stay Healthy

Blog banner

The House ??of Patola Designs: Traditional Weaves with a Modern Twist

Blog banner

The Five Steps of Data Science

Blog banner

Respondo Launches Revolutionary Video Discussion App

Blog banner

The IT Service Lifecycle

Blog banner

Worms, viruses and Bots

Blog banner

A Survey of Anti-Forensic Techniques: Methods, Challenges, and Countermeasures

Blog banner

Data Mapping

Blog banner

What is thread and alse multithreading

Blog banner

Impacts of Data Breach On Companies Challenges and Prevention

Blog banner

How International Schools Build Global-Minded Students through Curriculum & Activities

Blog banner

Artificial Intelligence and I

Blog banner

Deadlock

Blog banner

Answer

Blog banner

From Model Mistakes to Metrics

Blog banner

What your Favorite colour says about You?

Blog banner

Different Types of Data

Blog banner

Importance Of Yoga.

Blog banner