C Program to Calculate Discount on Bill Amount – C Exercise Program

C Program to Calculate Discount on Bill Amount एक बेहद popular और practically उपयोगी programming exercise है, जिसे हर C language सीखने वाले beginner को जरूर समझना चाहिए। यह program न सिर्फ आपको conditional statements का सही उपयोग सिखाता है, बल्कि real-world billing system का basic logic भी समझाता है।

इस post में आप step-by-step सीखेंगे कि कैसे C language में if–else if–else condition का उपयोग करके bill amount पर discount calculate किया जाता है। साथ ही आप समझेंगे कि variables कैसे declare होते हैं, user से input कैसे लिया जाता है, और percentage-based discount की गणना कैसे होती है।

यह guide specially उन beginners के लिए लिखी गई है जो C programming में decision making और arithmetic operations सीख रहे हैं। अंत तक पढ़ने के बाद आप खुद से एक functional billing discount calculator बना सकेंगे।

C Program to Calculate Discount on Bill Amount – क्यों सीखें?

आज के दौर में हर दुकान, mall, और online store पर bill amount के आधार पर discount दिया जाता है। जब आप C programming सीख रहे होते हैं, तो ऐसे real-life problems को code में implement करना आपकी logic-building को मजबूत बनाता है।

C Program to Calculate Discount on Bill Amount सीखने से आपको निम्नलिखित फायदे होते हैं:

  • Conditional Logic समझ में आती है — if, else if, else का practical उपयोग
  • Arithmetic Operations का अभ्यास होता है — percentage calculation
  • Float Data Type का सही उपयोग समझ में आता है
  • Real-world Programming Thinking develop होती है

Program Statement – Problem को समझें

इस program में हमें एक ऐसा C program बनाना है जो:

  1. User से Bill Amount input ले
  2. अगर Bill Amount ₹5000 या उससे अधिक हो → 20% discount दें
  3. अगर Bill Amount ₹3000 या उससे अधिक हो (लेकिन 5000 से कम) → 10% discount दें
  4. अगर Bill Amount ₹3000 से कम हो → कोई discount नहीं
  5. अंत में final payable amount print करें

यह logic real supermarkets और retail stores में भी इसी तरह काम करता है।

Program Code – C Program to Calculate Discount on Bill Amount

#include <stdio.h>


int main()
{
    float billAmount, discountAmount, finalAmount;


    printf("Enter Bill Amount: ");
    scanf("%f", &billAmount);


    // Calculate discount based on the bill amount
    if (billAmount >= 5000)
    {
        discountAmount = (20.0f / 100) * billAmount;
    }
    else if (billAmount >= 3000)
    {
        discountAmount = (10.0f / 100) * billAmount;
    }
    else
    {
        discountAmount = 0;
    }


    // Calculate the final amount after discount
    finalAmount = billAmount - discountAmount;


    // Display discount details
    if (discountAmount > 0)
    {
        printf("Congratulations! You got %.2f discount.\n", discountAmount);
        printf("You should pay: %.2f\n", finalAmount);
    }
    else
    {
        printf("No discount.\n");
        printf("You should pay: %.2f\n", finalAmount);
    }


    return 0;
}

Program Output – तीन Cases में देखें

Case 1: Bill Amount = ₹6000 (20% Discount)

▶️ Output Result
Enter Bill Amount : 6000 Congratulation! You got 1200.00 Discount You should Pay : 4800.00

Calculation: 6000 का 20% = 1200 → Final Amount = 6000 – 1200 = ₹4800

Case 2: Bill Amount = ₹3500 (10% Discount)

▶️ Output Result
Enter Bill Amount : 3500 Congratulation! You got 350.00 Discount You should Pay : 3150.00

Calculation: 3500 का 10% = 350 → Final Amount = 3500 – 350 = ₹3150

Case 3: Bill Amount = ₹2000 (No Discount)

▶️ Output Result
Enter Bill Amount : 2000 No Discount You should Pay : 2000.00

Calculation: 2000 < 3000 → कोई discount नहीं → Final Amount = ₹2000

Code Explanation – Line by Line समझें

1. Header File

#include <stdio.h>

यह standard input-output header file है। इसके बिना printf() और scanf() functions काम नहीं करते। हर C program की शुरुआत में यह लिखना जरूरी है।

2. Variables Declaration

float BillAmount, discountAmount, finalAmount;

तीन variables declare किए गए हैं:

  • BillAmount → User द्वारा enter किया गया bill amount store होता है
  • discountAmount → Calculate किया गया discount यहाँ store होता है
  • finalAmount → Discount घटाने के बाद जो amount बचती है वो यहाँ आती है

float datatype इसलिए use किया गया है क्योंकि bill amounts में decimal values भी आ सकती हैं, जैसे ₹3500.50

3. User से Input लेना

printf(“Enter Bill Amount : “);

scanf(“%f”, &BillAmount);

scanf(“%f”, &BillAmount) user द्वारा enter किया गया number BillAmount variable में store कर लेता है। %f format specifier float values के लिए use होता है।

4. Discount Logic – if–else if–else

यह program का सबसे महत्वपूर्ण हिस्सा है:

if (BillAmount >= 5000)
{
	discountAmount = (20.0 / 100) * BillAmount;
}
else if (BillAmount >= 3000)
{
	discountAmount = (10.0 / 100) * BillAmount;
}
else
{
	discountAmount = 0;
}

Condition की जाँच इस क्रम में होती है:

  1. पहले check होता है कि BillAmount ≥ 5000 है या नहीं → अगर हाँ, 20% discount
  2. अगर पहली condition false है, तो check होता है BillAmount ≥ 3000 → अगर हाँ, 10% discount
  3. दोनों false हों तो discount = 0

Important Note: 20.0 / 100 लिखा गया है न कि 20 / 100, क्योंकि अगर दोनों integer हों तो result 0 आ जाएगा। .0 लगाने से यह float division बन जाती है।

5. Final Amount Calculation

finalAmount = BillAmount – discountAmount;

Bill amount में से discount घटाने पर जो बचता है वही final payable amount होता है।

6. Output Display

printf(“Congratulation! You got %.2f Discount\n”, discountAmount);

printf(“You should Pay : %.2f\n”, finalAmount);

  • %.2f का मतलब है output को 2 decimal places तक दिखाना, जैसे 1200.00
  • अगर discount मिला तो congratulation message print होता है
  • अगर नहीं मिला तो “No Discount” print होता है

Program को और बेहतर कैसे बनाएं?

अगर आप इस C Program to Calculate Discount on Bill Amount को और advanced बनाना चाहते हैं, तो निम्न improvements कर सकते हैं:

  • Multiple discount slabs add करें (जैसे 30% for ₹10,000+)
  • GST calculation भी add करें final amount पर
  • Loop use करके multiple bills calculate करने की सुविधा दें
  • Coupon Code feature add करें जो extra discount दे
  • Output को formatted receipt की तरह print करें

if–else if–else vs Switch-Case – कब क्या use करें?

Featureif–else if–elseSwitch-Case
Range-based conditions✅ Best choice❌ उपयुक्त नहीं
Exact value matching✅ काम करता है✅ Best choice
Floating point support✅ हाँ❌ नहीं
Readability✅ अच्छी✅ बेहतर (कई cases में)

Discount calculation जैसे range-based problems के लिए हमेशा if–else if–else ही सबसे उपयुक्त होता है।

 Conclusion ( निष्कर्ष )

C Program to Calculate Discount on Bill Amount एक बेहतरीन beginner-level exercise है जो आपको C language के तीन सबसे जरूरी concepts — variables, conditional statements, और arithmetic operations — एक साथ practice करने का मौका देती है। इस program को समझने के बाद आप न सिर्फ discount calculator बल्कि tax calculator, grade calculator, और salary calculator जैसे programs भी आसानी से बना सकते हैं। Real-world logic को code में translate करने की यह ability आपको एक बेहतर programmer बनाती है।

अगर आप C programming को seriously सीखना चाहते हैं, तो इस code को खुद type करके compile करें, अलग-अलग values से test करें, और ऊपर बताए गए improvements को implement करने की कोशिश करें। Practice ही programming में mastery की असली कुंजी है। अगर कोई doubt हो तो नीचे comment करें — हम जरूर help करेंगे!

Frequently Asked Questions

Q 1: इस program में float की जगह int use करें तो क्या होगा?
Ans: अगर आप int use करते हैं तो decimal values handle नहीं होंगी। उदाहरण के लिए ₹3500.50 जैसी amount को program गलत तरीके से पढ़ेगा और discount calculation में error आ सकती है। इसलिए bill amount programs में हमेशा float या double use करना चाहिए।
Q 2: 20.0 / 100 की जगह 0.20 लिख सकते हैं?
Ans: हाँ, बिल्कुल। (0.20 * BillAmount) और (20.0 / 100 * BillAmount) दोनों एक ही result देते हैं। लेकिन 20.0 / 100 वाला तरीका code को ज्यादा readable और समझने में आसान बनाता है, खासकर beginners के लिए।
Q 3: क्या यह program negative bill amount के लिए भी काम करेगा?
Ans: Technically program run होगा, लेकिन negative amount का discount भी negative आएगा जो logically गलत है। एक robust program बनाने के लिए आपको input validation add करनी चाहिए, जैसे: if (BillAmount < 0) { printf("Invalid Amount!"); return 1; }
Q 4: अगर exactly ₹3000 enter करें तो कितना discount मिलेगा?
Ans: else if (BillAmount >= 3000) condition में >= (greater than or equal to) operator use हुआ है, इसलिए exactly ₹3000 पर भी 10% discount मिलेगा। Calculation: 3000 का 10% = 300 → Final = ₹2700।
Q 5: इस C Program को किसी real billing software में use कर सकते हैं?
Ans: यह program एक basic conceptual example है जो C programming के concepts सीखने के लिए है। Real billing software में database integration, multiple items, tax calculation, और user authentication जैसी बहुत सी advanced चीजें होती हैं। लेकिन इसका core discount logic same रहता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top