wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Product Discount Calculator

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

Cache Memory in Operating Systems

Blog banner

Are Social Media Paid Campaigns Worth It?

Blog banner

OS assignment 3

Blog banner

Telegram and it's features

Blog banner

FASHION

Blog banner

File management -disha parekh

Blog banner

Developments in Modern Operating Systems

Blog banner

Dos (Denial of service) Attack

Blog banner

Network Footprinting in Cybersecurity

Blog banner

IT security management

Blog banner

Hey Aryan here

Blog banner

Yahoo! mail

Blog banner

Spotify

Blog banner

Memory management

Blog banner

SPEM

Blog banner

How to insert contacts in zoho crm using php

Blog banner

Risk factors in service transistion

Blog banner

Amazon

Blog banner

Processes : Process description and control

Blog banner

Social media

Blog banner

The Rich Heritage Of Patola Sarees: Gujarat’s Timeless Weaving Art

Blog banner

Virtual memory

Blog banner

Beauty of indian railway

Blog banner

Classification Algorithms (Decision trees, SVM, Logistic regreession)

Blog banner

Operating system

Blog banner

VIRTUAL MEMORY

Blog banner

Different Types of Data

Blog banner

Malicious softwares

Blog banner

Linux -V Server Virtual Machine

Blog banner

Types of threads

Blog banner

Blockchain

Blog banner

GraphQL

Blog banner

Multiprocessor and Multicore Organization

Blog banner

Traveling

Blog banner

Deadlock and Starvation in an Operating System

Blog banner

Interrupts - Types, Working & Importance

Blog banner

Building a Simple Doctor Appointment System in Common Lisp

Blog banner

Vulnerability Assessment

Blog banner

Having passion in life

Blog banner

“Shot on iPhone” : A campaign by Apple that turned into a prodigy

Blog banner

Lifestyle of a photographer

Blog banner

Memory Hierarchy

Blog banner