C Program
#include <stdio.h> int main() { char p[20]; float price; int qty; scanf("%s %f %d", p, &price, &qty); float total = price * qty; if (qty > 5) total *= 0.9; printf("Bill: %.2f", total); }
C Output
Input:
Pen 10 6Output: Bill: 54.00
C++ Program
#include <iostream> using namespace std; int main() { string p; float price; int qty; cin >> p >> price >> qty; float total = price * qty; if (qty > 10) total *= 0.85; cout << "Bill: " << total; }
C++ Output
Input:
Notebook 20 12Output:
Bill: 204
JAVA Program
import java.util.*; public class Main { public static void main(String[] a) { Scanner s = new Scanner(System.in); String p = s.next(); float price = s.nextFloat(); int qty = s.nextInt(); float total = price * qty; if (qty > 3) total *= 0.95; System.out.printf("Bill: %.2f", total); } }
JAVA Output
Input:
Bottle 50 4
Output:
Bill: 190.00
Python Program
p, pr, q = input().split(); pr, q = float(pr), int(q) t = pr * q; t *= 0.9 if q > 8 else 1 print("Bill:", round(t, 2))
Python Output
Input:
Towel 25 10
Output:
Bill: 225.0
In-Depth Explanation
Example
When a customer purchases 6 pens costing ₹10 each, the bill is ₹60. As the number is greater than 5, there is a discount of 10%:
₹60 × 0.9 = ₹54. Therefore, the bill amounts to ₹54.
In the Java version, purchasing 4 bottles costing ₹50 each amounts to ₹200. A 5% discount is applicable:
₹200 × 0.95 = ₹190.
Real-Life Analogy
Consider a stationery store. If you purchase more than 5 products, you are offered a discount. The store computes total cost by multiplying quantity with unit price and adjusts it if you are eligible for a discount. That's what this program mimics.
Why It Matters
This program teaches dynamic billing — a term applied everywhere:
Retail stores
E-commerce websites
Restaurant billing
Inventory systems
It not only teaches multiplication of quantity and price but also conditional billing rules, such as discounts depending on quantity.
Learning Insights
You'll learn:
Arithmetic operations in programs
Applying if conditions to apply rules
Real billing logic in the real world
Input parsing and output formatting
Writing shortest working versions of actual applications
Every language parses input and outputs differently, but the billing logic is the same — granting you cross-language expertise in applying logic to real-world simulations.
Interview & Real-World Relevance
Interviewers usually ask billing system programs to verify:
Arithmetic accuracy
Conditional logic
Handling of edge-cases (such as no discount for small orders)
Output formatting (such as 2-decimal billing)
In actual real-world projects, this logic is found in:
Supermarket checkout counters
Online shopping product ordering systems
Point-of-sale (POS) applications
Inventory or invoice systems
One of the best entry-level programming exercises to grasp multiplication, conditional discounts, and user input is a billing system. This concise, real-life sample gets you ready for job interviews, coding competitions, and real-world app development. Whether creating for a store, kiosk, or e-commerce site, the logic in here lays the groundwork for real-time price calculation and payment processing.
Social Plugin