C Chapters

C Program to Create a structure to specify data of customers in a bank.The data to be stored is: Account number, Name, Balance in account.Assume maximum of 200 customers in the bank.
(a)Print the Account number and name of each customer with balance below Rs100.
(b)If a customer request for withdrawal or deposit, it is given in the form:
Acct. no, amount, code (1 for deposit, 0 for withdrawal)
Write a program to give a message, "The balance is insufficient for the specified withdrawal"

Arrays within Structure - Structures
#include <stdio.h>
#define n 25
struct bank
{
	int ac_num,balance;
	char name[50];
}b[n];//number of customer b[200]

int main()
{
	int i,choice,bal,acc,ch;
	printf("======================= $ Welcome to national bank $  =======================\n\n");
	printf("\t       ========= Please Input customers data  =========\n\n\n");
	for(i=0;i<=1;i++)
	{
		printf("Customer Account number : ");
		scanf("%d",&b[i].ac_num);
		printf("Customer Name : ");
		fflush(stdin);
		scanf("%s",&b[i].name);
		printf("Customer's Current Balance : ");
		scanf("%d",&b[i].balance);
		printf("\n----------------------\n\n");
	}
	printf("\n\n\n");
	printf("Hello Thank you for chosing our bank ! \n");
	printf("\nHow Can we help you ? \n");
	printf("1.Customers whoes balance is less than 100 : \n");
	printf("2.Transaction :");
	scanf("%d",&choice);
	switch(choice)
	{
		case 1:
			printf("\n================== Customer with low balance =================\n\n");
			for(i=0;i<=n;i++)
			{
				if(b[i].balance < 100)
				{
					printf("\nAccount Number : %d || Name : %s || Balance : %d",b[i].ac_num,b[i].name,b[i].balance);
		 		}
			}
			printf("\n\n\n===================== Please deposite soon ====================\n\n");
			break;
		case 2:
			printf("\nWhat would u like to do : \n\n");
			printf("1.Deposite : \n");
			printf("2.Withdraw : \n");
			scanf("%d",&ch);
			switch(ch)
			{
				case 1:
					printf("\nDear customer please input your Account Number : ");
					scanf("%d",&acc);
				for(i=0;i<=4;i++)
				{
					if(b[i].ac_num==acc)
					{
						printf("Hello : %s !\nEnter amount to be deposite : \n",b[i].name);
						scanf("%d",&bal);
						b[i].balance+=bal;
						printf("\n===========================================\n\n");
						printf("\nSuccessfully Deposited in your account \n");
						printf("\nAccount Number     : %d",b[i].ac_num);
						printf("\nName 	             : %s",b[i].name);
						printf("\nUpdated Balance is : %d",b[i].balance);
						printf("\n\n===========================================\n\n");
					}
				}
				break;
			case 2:
				printf("\nDear customer please input your Account Number : ");
				acc=0;
				scanf("%d",&acc);
				for(i=0;i<=4;i++)
				{
					if(b[i].ac_num==acc)
					{
						printf("Hello : %s !\nEnter amount to be withdraw: \n",b[i].name);
						scanf("%d",&bal);
						if(bal>b[i].balance)
						{
							printf("\nThe balance is insufficient for the specified withdrawal");
						}
						else
						{
							b[i].balance-=bal;
							printf("\n===========================================\n\n");
							printf("\nSuccessfully Withdraw in your account \n");
							printf("\nAccount Number     : %d",b[i].ac_num);
							printf("\nName 	             : %s",b[i].name);
							printf("\nUpdated Balance is : %d",b[i].balance);
							printf("\n\n===========================================\n\n");
						}
					}
				}
				break;
		}
	}
	return 0;
}

Output :
======================= $ Welcome to national bank $ =======================

========= Please Input customers data =========


Customer Account number : 110
Customer Name : George
Customer's Current Balance : 95

----------------------

Customer Account number : 56
Customer Name : Bob
Customer's Current Balance : 1200

----------------------




Hello Thank you for chosing our bank !

How Can we help you ?
1.Customers whoes balance is less than 100 :
2.Transaction :2

What would u like to do :

1.Deposite :
2.Withdraw :
2

Dear customer please input your Account Number : 110
Hello : George !
Enter amount to be withdraw:
500

The balance is insufficient for the specified withdrawal

===========================================================

Leave a comment
Recent Comments