![C-C++-Programming](https://connectkreations.com/wp-content/uploads/2023/02/C-C-Programming.jpg)
![C-C++-Programming](https://connectkreations.com/wp-content/uploads/2023/02/C-C-Programming.jpg)
Introduction
This program implements a basic banking system with a balance
variable that keeps track of the current balance. The deposit
function adds the specified amount
to the balance, the withdraw
function subtracts the specified amount
from the balance if it doesn’t cause the balance to go negative, and the check_balance
function displays the current balance. The main
function provides a menu-based interface for the user to perform these operations.
Implementation
- Initialize a variable
balance
to store the current balance of the account. - Create a menu-based interface for the user to perform various operations such as deposit, withdraw, and check balance.
- In the deposit operation, accept the amount from the user and add it to the current balance.
- In the withdraw operation, accept the amount from the user and subtract it from the current balance, but only if the balance after withdrawal is non-negative.
- In the check balance operation, display the current balance.
- Repeat steps 2 to 5 until the user chooses to exit the program.
Algorithm
- Initialize a variable
balance
to store the current balance of the account. - Create a menu-based interface for the user to perform various operations such as deposit, withdraw, and check balance.
- In the deposit operation, accept the amount from the user and add it to the current balance.
- In the withdraw operation, accept the amount from the user and subtract it from the current balance, but only if the balance after withdrawal is non-negative.
- In the check balance operation, display the current balance.
- Repeat steps 2 to 5 until the user chooses to exit the program.
Flow Chart
+---------------+
| Initialize |
| balance to 0 |
+---------------+
|
|
v
+---------------+
| Menu-based |
| interface |
+---------------+
|
|
+----+----+
| Deposit |
+-----------+
|
|
v
+---------------+
| Accept amount |
| and add to |
| balance |
+---------------+
|
|
+----+----+
| Withdraw |
+-----------+
|
|
v
+---------------+
| Accept amount |
| and subtract |
| from balance |
+---------------+
|
|
+----+----+
| Check |
| balance |
+-----------+
|
|
v
+---------------+
| Display |
| balance |
+---------------+
|
|
v
+---------------+
| Repeat from |
| step 2 |
+---------------+
C -Code Implementation: Method-Using Arrays
This is implemented using arrays
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int acc_no;
char acc_type;
char name[20];
float balance;
} account;
account customer[10];
// Initialization of array of structures
account customer[] = {
{0, 'S', "Amy", 1000.90},
{1, 'R', " Gail", 3000.50},
{2, 'C', "Marc", 5000},
{3, 'S', "Garry", 4000.80},
{4, 'S', " Cathy", 6000.3},
};
// For one customer, one array element which is a structure
float amt;
int arrayIndex;
int main()
{
int acctNum, choice;
int i, flag = 0;
printf("\n---------------------");
printf("\n Welcome to the KLS-GIT Bank");
printf("n-----------------------");
printf("\n\n Please enter your digitaccount number:");
scanf("%d", &acctNum);
// Checking whether the account number is valid
for (i = 0; i < 5; i++)
{
if (customer[i].acc_no == acctNum)
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("\n Sorry!!!! Invalid account number \n");
exit(0);
}
arrayIndex = acctNum ;
printf("\nAccount Number: %d\t Accounttype:%c\t\tName:%s", customer[arrayIndex].acc_no,
customer[arrayIndex].acc_type, customer[arrayIndex].name);
do
{
printf("\n\nPlease enter your choice: ");
printf("\n\n1:Balance Enquiry 2:Deposit 3:Withdraw 4:exit :");
scanf("%d", &choice);
switch(choice)
{
case 1:
balance();
break;
case 2:
deposit();
break;
case 3:
withdraw();
break;
default:
exit(0);
};
} while (1);
return 0;
}
void balance()
{
printf("\nbalance()....\n");
printf("\n\nYour Account balance is %0.2f", customer[arrayIndex].balance);
}
void deposit()
{
printf("\ndeposit()....\n");
printf("Please enter the amount to be deposited:");
scanf("%f", &amt);
customer[arrayIndex].balance += amt;
printf("\nRs.%0.2f is deposited in your account", amt);
printf("\n\nThe current balance is %0.2f",customer[arrayIndex].balance);
}
void withdraw()
{
printf("\nwithdrawl()....\n");
printf("\nEnter the amount to be withdrawn:");
scanf("%f", &amt);
if (amt > customer[arrayIndex].balance)
printf("\nNo sufficient balance\n");
else
{
customer[arrayIndex].balance -= amt;
printf("\nPlease collect your amount.\n\n The current balance is %0.2f\n",customer[arrayIndex].balance);
}
}
C -Code Implementation: Method Using case
#include <stdio.h>
float balance = 0.0;
void deposit(float amount) {
balance += amount;
printf("Deposited: %.2f\n", amount);
printf("New balance: %.2f\n", balance);
}
void withdraw(float amount) {
if (balance - amount >= 0) {
balance -= amount;
printf("Withdrew: %.2f\n", amount);
printf("New balance: %.2f\n", balance);
} else {
printf("Insufficient balance\n");
}
}
void check_balance() {
printf("Balance: %.2f\n", balance);
}
int main() {
int choice;
float amount;
while (1) {
printf("\nBanking System\n");
printf("1. Deposit\n");
printf("2. Withdraw\n");
printf("3. Check Balance\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter amount to deposit: ");
scanf("%f", &amount);
deposit(amount);
break;
case 2:
printf("Enter amount to withdraw: ");
scanf("%f", &amount);
withdraw(amount);
break;
case 3:
check_balance();
break;
case 4:
return 0;
default:
printf("Invalid choice\n");
}
}
return 0;
}
Explore More Projects on Matlab
- Text Analysis of Wikipedia Page – “Apple” using PythonText Analysis of Wikipedia Page – “Apple” 1. Introduction 1.1 Project Overview This project aims to perform a comprehensive text… Read more: Text Analysis of Wikipedia Page – “Apple” using Python
- Digital Communication Projects using MatlabDigital Communication Projects using Matlab. 1. Multiple Input Multiple Output(MIMO) using Matlab Output 2. Pulse Width Modulation(PWM) working Principal using… Read more: Digital Communication Projects using Matlab
- Write and execute a C++ program to implement the complex number classProblem Statement Write and execute a C++ program to implement the complex number class. Algorithm Here’s an algorithm for a… Read more: Write and execute a C++ program to implement the complex number class
- C++ and Python Program for Staff Management in Organization/CompanyYou need to create a base class called Manager and include all the general data members like name, age, employee… Read more: C++ and Python Program for Staff Management in Organization/Company
- C program that implements a simple banking systemIntroduction This program implements a basic banking system with a balance variable that keeps track of the current balance. The… Read more: C program that implements a simple banking system
Join us for Regular Updates
Telegram | Join Now |
Join Now | |
Join Now | |
Join Now | |
Join Now | |
Join our Telegram | connectkreations |
About Connect Kreations
We the team Connect Kreations have started a Blog page which is eminently beneficial to all the students those who are seeking jobs and are eager to develop themselves in a related area. As the world is quick on uptake, our website also focuses on latest trends in recent technologies and project learning and solutions. We are continuously putting our efforts to provide you with accurate, best quality, and genuine information. Here we also have complete set of details on how to prepare aptitude, interview and more of such placement/ off campus placement preparation.
Connect Kreations is excited to announce the expansion of our services into the realm of content creation! We are now offering a wide range of creative writing services, including poetry, articles, and stories.
Whether you need a heartfelt poem for a special occasion, a thought-provoking article for your blog or website, or an engaging story to captivate your audience, our team of talented writers is here to help. We have a passion for language and a commitment to creating high-quality content that is both original and engaging.
Our services are perfect for individuals, businesses, and organizations looking to add a touch of creativity and personality to their content. We are confident that our unique perspectives and diverse backgrounds will bring a fresh and exciting voice to your project.
Thank you for choosing Connect Kreations for your content creation needs. We look forward to working with you and helping you to bring your vision to life!
The website is open to all and we want all of you to make the best use of this opportunity and get benefit from it..🤓
- Our Websites: Connect Kreations
- Our Websites: StudentsDev Connect Kreations