C Example: Bank Accounts: deposit, withdraw, transfer and balance checks
Implements deposit, withdraw and account-to-account transfer with account structs; every operation first checks a positive amount and sufficient balance, printing a rejection instead of changing the balance. Prints final balances for three accounts, demonstrating validate-then-mutate.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
deposit 300.00 -> #1001 balance 1500.00 withdraw 700.00 from #1002 rejected (balance 540.50) withdraw 50.00 -> #1003 balance 30.00 transfer 200.00 #1001 -> #1003: 1300.00 / 230.00 deposit rejected: amount must be positive final balances: #1001 Ada 1300.00 #1002 Grace 540.50 #1003 Linus 230.00
🧩 Keep Learning