C Tutorial
This c program reads the deposit, withdraw amounts and computes the interest and balance based on the user inputs and selected operations sequences.
This c program uses switch case to handle different logics like deposit, withdraw, calculate interest and checking balance etc..
While loop is used to run the program indefinitely till user manually quit the program.
#include<stdio.h> void main() { int balance=0, deposit, withdraw; float ci; char op; while(1) { printf("\nBanking System"); printf("\n................"); printf("\nD ->Deposit"); printf("\nW ->Withdraw"); printf("\nB ->Balance"); printf("\nI ->Interest"); printf("\nQ ->Quit"); printf("\nEnter operation: "); scanf(" %c", &op); switch(op) { case 'D': printf("\nEnter deposit amount: "); scanf("%d", &deposit); balance += deposit; break; case 'W': printf("\nEnter withdraw amount: "); scanf("%d", &withdraw); balance -= withdraw; break; case 'B': printf("Balance: %d", balance); break; case 'I': ci = (float)balance*4/100; balance += ci; printf("\nInterest: %f", ci); break; case 'Q': return; default: printf("Invalid Operation!"); } } }
Output:
$ cc banking-system.c $ ./a.out Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: D Enter deposit amount: 70000 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: B Balance: 70000 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: W Enter withdraw amount: 25000 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: B Balance: 45000 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: I Interest: 1800.000000 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: B Balance: 46800 Banking System ................ D ->Deposit W ->Withdraw B ->Balance I ->Interest Q ->Quit Enter operation: Q $
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page