Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts.
#include<stdio.h>
int main()
{
float checking,savings,amount;
int choice1,choice2;
printf("Enter the intial amount in checking accout : ");
scanf("%f",&checking);
printf("Enter the intial amount in savings accout : ");
scanf("%f",&savings);
printf("\n1.Deposit\n2.Withdraw\n3.Transfer\n");
printf("Enter your choice : ");
scanf("%d",&choice1);
printf("Enter the account from which you want to do operation\n1.checking\n2.savings\n");
scanf("%d",&choice2);
if(choice2==1)
{
if(choice1==1)
{
printf("Enter the amount to deposit : ");
scanf("%f",&amount);
printf("Deposit successfull");
checking=checking+amount;
}
else if(choice1==2)
{
printf("Enter the amount to withdraw : ");
scanf("%f",&amount);
if(amount<checking)
{
printf("Withdraw successfull");
checking =checking-amount;
}
else
{
printf("Error!!! Insufficient Amount");
}
}
else if(choice1==3)
{
printf("Enter the amount to Transfer : ");
scanf("%f",&amount);
if(amount<checking)
{
printf("Transfer successfull");
checking =checking-amount;
}
else
{
printf("Error!!! Insufficient Amount");
}
}
else
{
printf("Enter correct choice.");
}
}
else if(choice2==2)
{
if(choice1==1)
{
printf("Enter the amount to deposit : ");
scanf("%f",&amount);
printf("Deposit successfull");
savings=savings+amount;
}
else if(choice1==2)
{
printf("Enter the amount to withdraw : ");
scanf("%f",&amount);
if(amount<savings)
{
printf("Withdraw successfull");
savings=savings-amount;
}
else
{
printf("Error!!! Insufficient Amount");
}
}
else if(choice1==3)
{
printf("Enter the amount to Transfer : ");
scanf("%f",&amount);
if(amount<savings)
{
printf("Transfer successfull");
savings=savings-amount;
}
else
{
printf("Error!!! Insufficient Amount");
}
}
else
{
printf("Enter correct choice.");
}
}
else
{
printf("The choice of bank account is wrong.");
}
printf("\nThe balance amount in checking account is %f.",checking);
printf("\nThe balance amount in savings account is %f.",savings);
}
Here is the above program that asks the user to enter the initial amonut of the bank account and display the options available and the when user selects one option then it will asks to select the operation and then acording to the enter values it will caluculate the operation for the selected bank account.
SCREENSHOT OF THE OUTPUT :
Get Answers For Free
Most questions answered within 1 hours.