wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Product Discount Calculator

profile
Vaishnavi Nayak
Sep 07, 2025
0 Likes
0 Discussions
1 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

MODERN OPERATING SYSTEM

Blog banner

Visualization in Data Science

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Virtual memory

Blog banner

Celebrate Diwali the Delicious Way with Meal Maharaj Catering

Blog banner

Fitness

Blog banner

Why Extreme Opinions Are Rising: Psychological Insights into Society’s Divides

Blog banner

The Benefits of Practical Life Activities in Preschool

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Data carving - using hex editor

Blog banner

This too shall pass

Blog banner

Operating system

Blog banner

Lemon and Chilli Pickle (Limbu Mirchi Achar)

Blog banner

10 Unknown facts about India's Independence

Blog banner

What is 'Multi-core and Multi-threading' ?

Blog banner

Everything You Need for a Perfect Stay in Arcadia, Florida, USA.

Blog banner

Decoding the Weave — How to Identify Original Patola Art on a Fabric

Blog banner

Data Visualization

Blog banner

Sagar Parikrama

Blog banner

Types of Threads

Blog banner

OS DESIGN CONSIDERATIONS FOR MULTIPROCESSOR

Blog banner

WINDOWS I/ O

Blog banner

The New Rules of UI/UX Design Every Website Must Follow in 2026

Blog banner

Smart Homes | Zigbee Alliance

Blog banner

Sage

Blog banner

Dekkers Algorithm

Blog banner

What is Packet Filtering?

Blog banner

38_Network Sniffing Techniques_SBC

Blog banner

Method of Evaluating Information Security Level in an Organization

Blog banner

Zero-Day Attack

Blog banner

Short-Form Video Marketing: Why It's Dominating the Internet

Blog banner

GUIDE TO GIS

Blog banner

Risk mitigation and management

Blog banner

Virtual Memory

Blog banner

CBSE + International Thinking: How Indian Schools Are Producing World-Ready Students

Blog banner

A Heartfelt Act of Kindness

Blog banner

Severe landslides continue to cause concern in Joshimath, Uttarakhand

Blog banner

Consumer to consumer Business model

Blog banner

Business Engineering

Blog banner

MACHINE LEARNING

Blog banner

Deadlock

Blog banner

Rain bow

Blog banner