Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loan Details also added #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 149 additions & 4 deletions bank management system.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include <math.h>

int i,j;
int main_exit;
void menu();
Expand All @@ -21,7 +23,7 @@ struct {
struct date deposit;
struct date withdraw;

}add,upd,check,rem,transaction;
}add,upd,temp,check,rem,transaction;

float interest(float t,float amount,int rate)
{
Expand Down Expand Up @@ -485,14 +487,108 @@ void see(void)
}

}
// Function to calculate the Equated Monthly Installment (EMI)
float calculate_emi(float loan_amount, float interest_rate, int tenure_years) {
float monthly_rate = interest_rate / (12 * 100); // Convert annual rate to monthly rate
int total_months = tenure_years * 12; // Convert tenure to months

return (loan_amount * monthly_rate * pow(1 + monthly_rate, total_months)) /
(pow(1 + monthly_rate, total_months) - 1);
}

// Function to apply for a loan
void apply_loan() {
int loan_choice, tenure_years;
float loan_amount, emi, interest_rate;
char confirm;

system("cls");
printf("\t\t\t\xB2\xB2\xB2 APPLY FOR LOAN \xB2\xB2\xB2\n\n");

printf("Select loan type:\n");
printf("1. Personal Loan (10%% annual interest)\n");
printf("2. Home Loan (6%% annual interest)\n");
printf("3. Education Loan (4%% annual interest)\n");
printf("Enter your choice (1-3): ");
scanf("%d", &loan_choice);

if (loan_choice < 1 || loan_choice > 3) {
printf("Invalid loan choice! Returning to main menu.\n");
fordelay(1000000000); // Optional delay to give the user time to read the message
menu(); // Call the menu function to return to the main menu
return;
}

printf("Enter the loan amount: $");
scanf("%f", &loan_amount);

if (loan_amount <= 0) {
printf("Invalid loan amount! Returning to main menu.\n");
return;
}

printf("Enter the loan tenure (in years): ");
scanf("%d", &tenure_years);

if (tenure_years <= 0) {
printf("Invalid loan tenure! Returning to main menu.\n");
return;
}

// Determine the interest rate based on loan choice
switch (loan_choice) {
case 1:
interest_rate = 10.0; // Personal Loan
printf("\nYou have selected Personal Loan with 10%% annual interest.\n");
break;
case 2:
interest_rate = 6.0; // Home Loan
printf("\nYou have selected Home Loan with 6%% annual interest.\n");
break;
case 3:
interest_rate = 4.0; // Education Loan
printf("\nYou have selected Education Loan with 4%% annual interest.\n");
break;
default:
printf("Enter ");
}

// Calculate the EMI
emi = calculate_emi(loan_amount, interest_rate, tenure_years);

// Display loan summary
printf("\nLoan Summary:\n");
printf("Loan Amount: $%.2f\n", loan_amount);
printf("Interest Rate: %.2f%% per annum\n", interest_rate);
printf("Tenure: %d years\n", tenure_years);
printf("Equated Monthly Installment (EMI): $%.2f\n", emi);
printf("Total Repayment Amount (including interest): $%.2f\n", emi * tenure_years * 12);

// Confirm loan application
printf("\nDo you want to proceed with the loan application? (Y/N): ");
getchar(); // To consume any leftover newline character from previous inputs
scanf("%c", &confirm);

if (confirm == 'Y' || confirm == 'y') {
printf("\nLoan application submitted successfully!\n");
printf("Your monthly EMI will be $%.2f for %d months.\n", emi, tenure_years * 12);
} else {
printf("\nLoan application canceled.\n");
}

// Wait for user input before returning to the main menu
printf("\nPress enter to return to the main menu...\n");
getchar();
getchar();
menu();
}
void menu(void){
int choice;
system("cls");
system("color 9");
printf("\n\n\t\t\tCUSTOMER ACCOUNT BANKING MANAGEMENT SYSTEM");
printf("\n\n\n\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO THE MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2");
printf("\n\n\t\t1.Create new account\n\t\t2.Update information of existing account\n\t\t3.For transactions\n\t\t4.Check the details of existing account\n\t\t5.Removing existing account\n\t\t6.View customer's list\n\t\t7.Transfer funds\n\t\t8.Exit\n\n\n\n\n\t\t Enter your choice:");
printf("\n\n\t\t1.Create new account\n\t\t2.Update information of existing account\n\t\t3.For transactions\n\t\t4.Check the details of existing account\n\t\t5.Removing existing account\n\t\t6.View customer's list\n\t\t7.Transfer funds\n\t\t8.Apply for loan\n\t\t9.Exit\n\n\n\n\n\t\t Enter your choice:");
scanf("%d", &choice);

system("cls");
Expand All @@ -518,7 +614,56 @@ void menu(void){
case 7:
transfer();
break;
case 8:
case 8: {
FILE *ptr;
int account_found = 0; // Flag to check if account exists

ptr = fopen("record.dat", "r");
if (ptr == NULL) {
printf("Error opening file!\n");
Sleep(3000);
menu(); // Return to menu if file cannot be opened
break;
}

printf("Enter Account No.: ");
scanf("%d", &check.acc_no);

// Loop through the file to find the matching account number
while (fscanf(ptr, "%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",
&add.acc_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year,
&add.age, add.address, add.citizenship, &add.phone, add.acc_type,
&add.amt, &add.deposit.month, &add.deposit.day, &add.deposit.year) != EOF) {

if (add.acc_no == check.acc_no) {
// Account number found
account_found = 1;
printf("Account found!\n");

// Get phone number and DOB from the user
printf("Enter phone: ");
scanf("%lf", &add.phone); // Use %lf for double
printf("Enter Date Of Birth (MM/DD/YYYY): ");
scanf("%d/%d/%d", &add.dob.month, &add.dob.day, &add.dob.year);

// Call apply_loan() function after collecting details
apply_loan();

break; // Exit the loop after finding the account
}
}

if (!account_found) {
printf("Account no. does not exist.\n");
Sleep(3000); // Delay for 3 seconds
menu(); // Return to the main menu
}

fclose(ptr); // Close the file after processing
break;
}

case 9:
exit(0);
break;
}
Expand Down Expand Up @@ -643,7 +788,7 @@ int main()
{printf("\nInvalid!");
fordelay(1000000000);
system("cls");
goto login_try;}
}

}
return 0;
Expand Down
Binary file added bank_management.exe
Binary file not shown.
4 changes: 4 additions & 0 deletions record.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
423 42 4234/0/0 234 234 2234 234.000000 1 234.000000 23423/0/0
213 sal 1/1/2005 234 hk hj 234.000000 bjhb 234.000000 23423/0/0
123 sal 1/1/20204 12 123 12 123.000000 1 123.000000 23423/0/0
9087 mia 12/12/2002 20 xyz 123 456.000000 1 30000.000000 23423/0/0