wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Product Discount Calculator

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

Ethical Hacking

Blog banner

From Procrastinator to Performer: How to Beat the Last-Minute Rush

Blog banner

Virtual Machine

Blog banner

Deadlock and Starvation

Blog banner

The Art of Slow Fashion: Why Patola Defines Sustainable Luxury

Blog banner

Vulnerability Assessment

Blog banner

Apache Spark :- Powerful Data Processing Tool

Blog banner

Best password managers: Reviews of the top products

Blog banner

Hypothesis Testing in Data Science

Blog banner

12 Principles of Animation

Blog banner

Critical success factors

Blog banner

Cloud Forensic Tools And Storage :A Review Paper

Blog banner

HACKING MOBILE PLATFORM

Blog banner

"Audit" In Data Science

Blog banner

Data Security and Data Privacy in Data Science

Blog banner

Principles of Service Operation

Blog banner

Sage business cloud accounting

Blog banner

Network Forensics

Blog banner

Multicore and Multithreading

Blog banner

Hosting basics

Blog banner

Real time scheduling

Blog banner

A Brief Review on Cyber Forensics and its Analysis Tool

Blog banner

Types of Hackers.

Blog banner

Importance of education

Blog banner

Data Storytelling: Turning Analysis into Business Action

Blog banner

Concept and definition of m-commerce

Blog banner

Social Network Analysis: Ek Naya Nazariya Data Science Mein

Blog banner

Navigation With Indian Constellation(NavIC) by ISRO in Geographic Information Systems

Blog banner

AI and Data Science: Revolutionizing Industries

Blog banner

Risk mitigation and management

Blog banner

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

Blog banner

The Importance of Financial Literacy for College Students

Blog banner

The 60-Minute Window: What to Do (And What NOT to Do) When You Knock Out a Tooth

Blog banner

Technical SEO : Total Guide

Blog banner

Deadlock and starvation in operating system

Blog banner

Paginng In OS

Blog banner

Pandas Matrix Applications

Blog banner

Mumbai local ......

Blog banner

From Loom to Luxury: How Patola Elevates Modern Wardrobes

Blog banner

MODERN OPERATING SYSTEM

Blog banner

How to feel Happy everyday day

Blog banner

MEMORY HIERARCHY

Blog banner