Code:
#include <stdio.h>
#include <time.h> //HEADER FILES
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <Windows.h>
void display_main_menu(void);
void create_account(void);
void modify_account(void); //FUNCTION DECLARATIONS
void make_withdrawal(void);
void make_deposit(void);
void display_logo(void);
void exit_program(void);
FILE *acc; //FILE DECLARATION
typedef struct //STRUCTURE
{
char firstname[200];
char lastname[200];
char password[200];
char parish[200];
int payment_type;
int account_num;
int age_calculation;
int yob;
float acc_bal;
float acc_fee;
float acc_change;
float change_from_fee;
}Accounts;
Accounts students={"","","","",0,0,0,0,0,0,0,0}; //INITIALIZING THE STRUCTURE'S ELEMENTS
main() //MAIN STARTS HERE
{
SetConsoleTitle("Program done by Nicholas Cameron...Banking Agency");
int program_pass=2014; //Password needed to access the program
int pass=0;
char option;
display_logo();
do //CODES FOR ENTERING THE PASSWORD
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("Enter password ");
scanf("%d", &pass);
fflush(stdin);
if(pass!=program_pass)
printf("\nAccess Denied! \nPassword incorrect. Please try again ");
}
while (pass!=program_pass);
while (pass==program_pass) // while loop for when password entered is correct
{
printf(" \nAccess Granted!\n");
printf("\n\nPress enter to continue");
getch();
system("cls");
display_main_menu();
}
system("pause");
exit(1);
}//MAIN ENDS HERE
//FUNCTION DEFINITIONS
void display_main_menu(void) //function display main menu
{
main_menu: // goto LABEL FOR MAIN MENU
system("cls");
char activity_selection;
display_logo();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("Please select from the list below the action you wish to carry out\n\n\t");
printf(" || A. Create an account -(Preferably for new users) ||\n\t");
printf(" || B. Make a deposit -(for members only) ||\n\t");
printf(" || C. Make a withdrawal -(for members only) ||\n\t");
printf(" || D. Modify an account -(for members only) ||\n\t");
printf(" || E. Exit -(for all users) ||\n\n");
printf("Enter the letter that corresponds with each option\n");
scanf("%s",&activity_selection);
system("cls");
switch(activity_selection)
{
case 'A': case'a':
create_account();
break;
case 'B': case 'b': //DEPOSIT PROCESS
make_deposit();
break;
case 'C': case 'c': //WITHDRAWAL PROCESS
make_withdrawal();
break;
case 'D': case 'd': //Modifying PROCESS
modify_account();
break;
case 'E': case 'e': //Exit process
exit_program();
break;
default :
system("cls");
printf("The choice you entered appears to be invalid\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
printf("\n\t || A.<MAIN MENU> ||\n\t");
printf(" || B.<EXIT> ||\n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("Please enter the corresponding letter for the task you wish to execute\n\n\n");
scanf("%s",&activity_selection);
if(activity_selection=='A'||activity_selection=='a')
{
goto main_menu; //THIS MOVES TO THE MAIN MENU IF 'A' OR 'a' IS ENTERED.DIDNT CALL THE display_main_menu() FUNCTION SINCE WE'RE ALREADY INSIDE IT
}
else if(activity_selection=='B'||activity_selection=='b')
{
exit(1); //Exits the program if exit is selected
}
else
{
printf("Another invalid option entered.Thank you for trying to use this program\n");
printf("Press any key to exit\n");
getch();
exit(1);
}
break;
}
}
void create_account(void) //function create account
{
int current_year=2014;
char decision,new_choice,payment_plan;
int r;
srand((unsigned)time(0));//UNSIGNED PREVENTS RANDOM NEGATIVE NUMBERS FROM GENERATING
r=(rand()*999999999);
r=(rand()%9999999999999)+1;
students.account_num=r;
decision='y';
do
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("This is a list of our current savings plan system which you will choose from\n");
printf("\n\t || A. One year ||\n\t");
printf(" || B. Two years ||\n\t");
printf(" || C. Three years ||\n\t");
printf(" || D. Four years ||\n\t");
printf(" || E. Five years ||\n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("Please note...you should enter the corresponding number for the desired savings plan\n");
printf("You may now enter the savings plan desired\n");
scanf("%s",&payment_plan);
fflush(stdin);
switch(payment_plan)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
case 'A': case'a':
printf("You have decided to use a savings plan of 1 year\n");
students.payment_type=1;
break;
case 'B': case'b':
printf("You have decided to use a savings plan of 2 years\n");
students.payment_type=2;
break;
case 'C': case'c':
printf("You have decided to use a savings plan of 3 years\n");
students.payment_type=3;
break;
case 'D': case'd':
printf("You have decided to use a savings plan of 4 years\n");
students.payment_type=4;
break;
case 'E': case'e':
printf("You have decided to use a savings plan of 5 years\n");
students.payment_type=5;
break;
default:
system("cls");
printf("Invalid option entered\n");
printf("Press any key to continue\n");
getch();
system("cls");
display_main_menu();
break;
}
printf("A minimum opening fee of $100 is required\n");
printf("Enter the minimum opening fee\n");
scanf("%f",&students.acc_fee);
if(students.acc_fee<100)
{
printf("The fee entered is too low\n");
printf("Press enter to return to the main menu\n");
getch();
display_main_menu();
}
else if(students.acc_fee<=100)
{
printf("Your account balance is $%.2f.It will be saved in your creating account\n",students.acc_fee);
printf("Press enter to continue\n");
getch();
}
else if(students.acc_fee>100)
{
students.acc_change=students.acc_fee-100;
printf("You have an existing change of $%.2f",students.acc_change);
printf("\nIf you wish to retrieve it, a withdrawal must be made after the account has been created\n");
printf("Press enter to continue\n");
getch();
}
students.change_from_fee=students.acc_change;
students.acc_bal=students.acc_fee;
system("cls");
printf("it is now time to create an account please enter the information required\n\n");
printf("enter your firstname\n");
scanf("%s",&students.firstname);
printf("enter your lastname\n");
scanf("%s",&students.lastname);
printf("Enter the name of your parish\n");
scanf("%s",&students.parish);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("\nTo sign up with us, ages must be 12 or older but less than 20 years of age\n"); //In most high schools ages range from approximately 12-20 years
printf("You may now enter your year of birth\n");
scanf("%d",&students.yob);
students.age_calculation = current_year-students.yob;
printf("Your age is %d ",students.age_calculation);
if(students.age_calculation >= 12 && students.age_calculation<=20)
{
printf("Which is an acceptable age\n");
printf("Please enter a password\n");
scanf("%s",&students.password);
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("Please Hold, Creating Account...");
/*Sleep(3000);
system("cls");
printf("Accepting Data....");
Sleep(300);
system("cls");
printf("Enabling Data De-Fragmentation.....");
Sleep(100);
system("cls");
printf("Organizing File Memory...");
Sleep(300);
system("cls");
printf("Initiating Data Logs...");
Sleep(200);
system("cls");
printf("Data Checking...");
Sleep(200);
system("cls");
printf("Initializing Validity Check...");
Sleep(100);
system("cls");
printf("Locating Account Addresses..");
Sleep(200);
system("cls");
printf("Initiating Data Storage...");
Sleep(300);
system("cls");
printf("Finalizing DataBase Entry...");
Sleep(2000);*/
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("Your account has been successfully created!\n");
printf("You have been assigned the account number :");
printf("%d",students.account_num);
printf("\n\nKeep your account number safe for it will be needed for account access\n\n");
printf("Your information is as follows:\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
acc=fopen("Active Accounts.txt","a+");// FILE HOLDING THE SUCCESSFULLY CREATED ACCOUNTS
if (acc==NULL)
{
printf("ERROR OPENING FILE!\n");
printf("Press enter to continue");
getch();
display_main_menu();
}
fprintf(acc,"%d",students.account_num);
fprintf(acc,"%s",students.firstname);
fprintf(acc,"%s",students.lastname);
fprintf(acc,"%s",students.parish);
fprintf(acc,"%d",students.yob);
fprintf(acc,"%d",students.age_calculation);
fprintf(acc,"%d",students.payment_type);
fprintf(acc,"%s",students.password);
fprintf(acc,"%.2f",students.acc_bal);
fclose(acc);
printf("================================================================================");
printf(" >> Account # : %d\n",students.account_num);
printf(" >> First Name : %s\n",students.firstname);
printf(" >> Last Name : %s\n",students.lastname);
printf(" >> Parish : %s\n",students.parish);
printf(" >> Year of Birth : %d\n",students.yob);
printf(" >> Age : %d\n",students.age_calculation);
printf(" >> Savings Period : %d year(s)\n",students.payment_type);
printf(" >> Password : %s\n",students.password);
printf(" >> Account balance : $%.2f\n",students.acc_bal);
printf("================================================================================\n");
}
else if(students.age_calculation >20)
{
printf("Were very sorry but you are too old to create an account with us\n\n");
}
else if(students.age_calculation <12)
{
printf("You are too young to create an account here sorry\n\n");
}
printf("If a mistake was made you can repeat the procedure of creating another savings\n");
printf("account\n\n");
printf("Do you wish to repeat? <y or n>\n\n");
scanf("%s",&decision);
system("cls");
}
while(decision=='Y'||decision=='y');
if(decision=='N'||decision=='n')
{
printf("You are now a member of this banking agency!\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
main_or_exit:
printf("\n\t || A.<MAIN MENU> ||\n\t");
printf(" || B.<EXIT> ||\n\n");
printf("Please select the desired option <a or b>\n\n");
scanf("%s",&new_choice);
if(new_choice=='A'||new_choice=='a')
{
display_main_menu();
}
else if(new_choice=='B'||new_choice=='b')
{
exit(1);
}
else
{
system("cls");
printf("Invalid option entered\n");
printf("Please read carefully and re-enter the option desired\n");
goto main_or_exit;
}
}
}
void make_withdrawal(void) //function make a withdrawal from an account
{
system("cls");
display_logo();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("\n\nWITHDRAWAL PROCESSING IS DONE HERE\n\n");
printf("PRESS ENTER TO CONTINUE");
getch();
system("cls");
int id=0;
float withdraw=0;
if((acc=fopen("Active Accounts.txt","r"))==NULL)
{
printf("\nERROR OPENING FILE.");
printf("Press enter to continue");
getch();
display_main_menu();
}
printf("Please enter your account number\n");
scanf("%d",&id);
rewind(acc);
fseek(acc,(id -1) *sizeof (Accounts), SEEK_SET);
fread(&students, sizeof(Accounts), 1, acc);
if(id!=students.account_num)
{
printf("ACCOUNT WAS NOT FOUND\n");
printf("Press enter to return to the main menu");
getch();
display_main_menu();
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("ACCOUNT FOUND!");
printf("\n================================================================================");
printf(" >> Account # : %d\n",students.account_num);
printf(" >> First Name : %s\n",students.firstname);
printf(" >> Last Name : %s\n",students.lastname);
printf(" >> Parish : %s\n",students.parish);
printf(" >> Year of Birth : %d\n",students.yob);
printf(" >> Age : %d\n",students.age_calculation);
printf(" >> Savings Period : %d year(s)\n",students.payment_type);
printf(" >> Password : %s\n",students.password);
printf(" >> Account balance : $%.2f\n",students.acc_bal);
printf("================================================================================\n");
}
fflush(stdin);
withdrawal:
printf("Enter the amount of money you wish to withdraw\n");
scanf("%f",&withdraw);
if(withdraw>students.acc_bal)
{
printf("The amount you entered is too high it must be less than or equal to your balance\n");
printf("which is $%.2f\n",students.acc_bal);
printf("Press enter to re-enter the withdrawal value\n");
getch();
goto withdrawal;
}
else if(withdraw<=students.acc_bal && withdraw>0)
{
students.acc_bal=students.acc_bal-withdraw;
printf("WITHDRAWAL WAS SUCCESSFUL\n");
printf("YOUR ACCOUNT BALANCE IS $%.2f",students.acc_bal);
printf("Press enter to continue\n");
getch();
display_main_menu();
}
else if(withdraw<=0)
{
printf("The amount you entered is too low\n");
printf("Press enter to re-enter the withdrawal value\n");
getch();
goto withdrawal;
}
fclose(acc);
}
void make_deposit(void) //function make deposit to an account
{
system("cls");
display_logo();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("\n\nDEPOSIT PROCESSING IS DONE HERE\n\n");
printf("PRESS ENTER TO CONTINUE");
getch();
system("cls");
int id;
float deposit=0;
if((acc=fopen("Active Accounts.txt","r"))==NULL)
{
printf("\nERROR OPENING FILE.");
printf("Press enter to continue");
getch();
display_main_menu();
}
printf("Please enter your account number\n");
scanf("%d",&id);
rewind(acc);
fseek(acc,(id -1) *sizeof (Accounts), SEEK_SET);
fread(&students, sizeof (Accounts), 1, acc);
if(id!=students.account_num)
{
printf("ACCOUNT WAS NOT FOUND\n");
printf("Press enter to return to the main menu\n");
getch();
display_main_menu();
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("ACCOUNT FOUND!");
printf("\n================================================================================");
printf(" >> Account # : %d\n",students.account_num);
printf(" >> First Name : %s\n",students.firstname);
printf(" >> Last Name : %s\n",students.lastname);
printf(" >> Parish : %s\n",students.parish);
printf(" >> Year of Birth : %d\n",students.yob);
printf(" >> Age : %d\n",students.age_calculation);
printf(" >> Savings Period : %d year(s)\n",students.payment_type);
printf(" >> Password : %s\n",students.password);
printf(" >> Account balance : $%.2f\n",students.acc_bal);
printf("================================================================================\n");
}
fflush(stdin);
deposits:
printf("Enter the amount of money you wish to deposit\n");
scanf("%f",&deposit);
if(deposit<=0)
{
printf("Were very sorry but you cannot deposit $0 or less\n");
printf("Press enter to re-enter the deposit amount\n");
getch();
goto deposits;
}
else
{
students.acc_bal=students.acc_bal+deposit;
printf("DEPOSIT WAS SUCCESSFUL\n");
printf("YOUR ACCOUNT BALANCE IS $%.2f\n",students.acc_bal);
printf("Press enter to continue");
getch();
display_main_menu();
}
fclose(acc);
}
void modify_account(void) //function modify an account
{
system("cls");
display_logo();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
int id;
printf("\n\nMODIFYING ACCOUNTS IS DONE HERE\n\n");
printf("PRESS ENTER TO CONTINUE");
getch();
system("cls");
char an='y';
if((acc=fopen("Active Accounts.txt","r"))==NULL)
{
printf("\nERROR OPENING FILE.");
printf("Press enter to continue");
getch();
display_main_menu();
}
printf("Please enter your account number\n");
scanf("%d",&id);
rewind(acc);
fseek(acc,(id -1) *sizeof (Accounts), SEEK_SET);
fread(&students, sizeof (Accounts), 1, acc);
if(id!=students.account_num)
{
printf("ACCOUNT WAS NOT FOUND\n");
printf("Press enter to return to the main menu\n");
getch();
display_main_menu();
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("THIS IS YOUR CURRENT ACCOUNT INFORMATION!");
printf("\n================================================================================");
printf(" >> Account # : %d\n",students.account_num);
printf(" >> First Name : %s\n",students.firstname);
printf(" >> Last Name : %s\n",students.lastname);
printf(" >> Parish : %s\n",students.parish);
printf(" >> Year of Birth : %d\n",students.yob);
printf(" >> Age : %d\n",students.age_calculation);
printf(" >> Savings Period : %d year(s)\n",students.payment_type);
printf(" >> Password : %s\n",students.password);
printf(" >> Account balance : $%.2f\n",students.acc_bal);
printf("================================================================================\n");
}
fflush(stdin);
printf("Members can modify only the following fields:\n");
printf("First Name\n");
printf("Last Name\n");
printf("Parish\n");
printf("Password\n");
an_option:
printf("do you wish to proceed with modifications? <y or n>\n");
scanf("%s",&an);
if(an=='Y'||an=='y')
{
printf("Enter the first name\n");
scanf("%s",students.firstname);
printf("Enter the new last name\n");
scanf("%s",students.lastname);
printf("Enter the name of your new parish\n");
scanf("%s",students.parish);
printf("Enter the new password\n");
scanf("%s",students.password);
fflush(stdin);
printf("Press enter to continue\n");
getch();
system("cls");
printf("Your Account has been successfully modified.Your new Information is as follows\n\n");
printf("\n================================================================================");
printf(" >> Account # : %d\n",students.account_num);
printf(" >> First Name : %s\n",students.firstname);
printf(" >> Last Name : %s\n",students.lastname);
printf(" >> Parish : %s\n",students.parish);
printf(" >> Year of Birth : %d\n",students.yob);
printf(" >> Age : %d\n",students.age_calculation);
printf(" >> Savings Period : %d year(s)\n",students.payment_type);
printf(" >> Password : %s\n",students.password);
printf(" >> Account balance : $%.2f\n",students.acc_bal);
printf("================================================================================\n");
fflush(stdin);
printf("Press enter to return to the main menu\n");
getch();
display_main_menu();
}
else if(an=='N'||an=='n')
{
printf("As you wish....Press enter to return to the main menu\n");
getch();
display_main_menu();
}
else
{
printf("Invalid answer.Press enter to re-enter the option\n");
getch();
goto an_option;
}
fclose(acc);
}
void display_logo(void)//function to display logo
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("\t =================================================== \n\t");
printf(" @@@@@@@@@@ THE OLD HARBOUR @@@@@@@@@@@@@@@@ \n\t");
printf(" @@@@@@@@@@ HIGH SCHOOL BANKING @@@@@@@@@@@@@@@@ \n\t");
printf(" @@@@@@@@@@ SYSTEM @@@@@@@@@@@@@@@@ \n\t");
printf(" =================================================== \n\n");
}
void exit_program(void)
{
system("cls");
display_logo();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("Thank you for using this program\n");
printf("Press any key to exit\n");
getch();
exit(1);
}