इस program में आप सीखेंगे कि C Program for ATM withdrawal system को C language में कैसे implement किया जाता है। यहाँ user से balance और withdraw amount input लिया जाता है, फिर कुछ conditions check की जाती हैं – जैसे invalid amount, insufficient balance और minimum balance maintain करना।
इस program से beginners को if-else conditions, comparison operators और basic banking logic समझने में मदद मिलेगी। साथ ही यह भी सीखेंगे कि real-world problem को code में कैसे convert किया जाता है। यह example खासतौर पर उन students के लिए useful है जो C programming की शुरुआत कर रहे हैं और practical programs बनाना चाहते हैं।
Program Statement
एक ऐसा C program लिखिए जो user से account balance और withdraw amount input ले।
Program को निम्न conditions check करनी हैं:
- अगर withdraw amount 0 या उससे कम है तो “Invalid withdraw amount” दिखाए।
- अगर withdraw amount balance से ज्यादा है तो “Insufficient balance” दिखाए।
- अगर withdraw करने के बाद remaining balance 1000 से कम हो जाता है तो “Minimum balance of 1000 must be maintained” दिखाए।
- अन्यथा cash देने का message और remaining balance display करे।
Program Code
#include <stdio.h>
int main()
{
float balance, withdraw, remaining;
printf("Enter Balance: ");
scanf("%f", &balance);
printf("Enter Withdraw amount: ");
scanf("%f", &withdraw);
remaining = balance - withdraw;
if (withdraw <= 0)
{
printf("Invalid withdraw amount\n");
}
else if (withdraw > balance)
{
printf("Insufficient balance\n");
}
else if (remaining < 1000)
{
printf("Minimum balance of 1000 must be maintained\n");
}
else
{
printf("Take your cash\n");
printf("Remaining balance: %.2f\n", remaining);
}
return 0;
}
Program Output :
Case 1:
Enter Balance: 5000
Enter Withdraw amount: 2000
Take your cash
Remaining balance: 3000.00
Case 2:
Enter Balance: 5000
Enter Withdraw amount: 4500
Minimum balance of 1000 must be maintained
Case 3:
Enter Balance: 5000
Enter Withdraw amount: 6000
Insufficient balance
Case 4:
Enter Balance: 5000
Enter Withdraw amount: -200
Invalid withdraw amount
Code Explanation
सबसे पहले stdio.h header file include की गई है ताकि printf और scanf functions का उपयोग किया जा सके।
float balance, withdraw, remaining;
यहाँ तीन variables declare किए गए हैं:
- balance – user का total account balance store करने के लिए
- withdraw – withdraw की जाने वाली राशि store करने के लिए
- remaining – withdrawal के बाद बची हुई राशि calculate करने के लिए
remaining = balance – withdraw;
यह statement withdrawal के बाद remaining balance calculate करता है।
इसके बाद if-else if condition structure use किया गया है:
- withdraw <= 0 → invalid amount को handle करता है।
- withdraw > balance → insufficient balance check करता है।
- remaining < 1000 → minimum balance condition check करता है।
- अगर ऊपर की कोई condition true नहीं होती, तो withdrawal successful माना जाता है।
%.2f format specifier दो decimal places तक balance show करता है, जिससे output professional दिखता है।
यह program real banking system का simplified version है, लेकिन logic समझने के लिए बहुत अच्छा example है।
