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

My favourite food

Blog banner

Why Khari and toast is the ideal Tea Break snack?

Blog banner

From Airboat Tours to Fossil Hunting: The Ultimate Arcadia Travel Experience

Blog banner

IT Service as as Value Creation

Blog banner

E-learning in today's world

Blog banner

Understanding - Proof of Work!

Blog banner

Advantage of freedom

Blog banner

Elements and Principles of Photography

Blog banner

Importance of self defence for girls

Blog banner

USPS mail

Blog banner

Teenagers of Today

Blog banner

Best Time to Visit Arcadia, Florida & Why Oak Tree Hotel Is Always Ready

Blog banner

Interesting fact about kangaroo.

Blog banner

Life of a 2020-2021 student

Blog banner

Use It or Lose It: Why November Is the Best Time to Claim Your Dental Extras and Medicare CDBS Before Year-End

Blog banner

Paginng In OS

Blog banner

Emerging threats in cyber Forensics

Blog banner

?What Children Learn Between Activities: The Hidden Learning Moments in a Preschool Day

Blog banner

Concurrency and Deadlocks

Blog banner

Principles of Concurrency

Blog banner

Know your Processors!

Blog banner

Title: Network Sniffing Techniques: Uncovering the Secrets of Data Transfer

Blog banner

RAID

Blog banner

INTERNET SECURITY

Blog banner

Geographic Information Systems(By aditi Unnikrishnan)

Blog banner

Little Habits, Big Impact: Daily Preschool Routines That Shape the Future

Blog banner

virtual machine

Blog banner

RAID

Blog banner

Friendship

Blog banner

CyberSecurity Color Wheel

Blog banner

Introduction to Data Science: Life Cycle & Applications

Blog banner

FILE SHARING

Blog banner

Man VS Nature

Blog banner

Sessions In OS.

Blog banner

Vulnerability Assessment (Vulnerability Analysis)

Blog banner

The art of being alone

Blog banner

Yoga in INDIA and ABROAD

Blog banner

Evolution of the Microprocesor

Blog banner

Blog on health and fitness

Blog banner

THE DESIRE OF MANY

Blog banner

Understanding Loneliness: Why We Feel Disconnected in a Connected World (Part -1)

Blog banner

Modern operating system

Blog banner