This is a working program: If you create an Account then try to create another Account, it prompts: Account Already Existing. After you close the Account, you should be able to create a new Account but instead it prompts Account Already Existing. Need assistance on the logic. Issue on the Open Account and Close Account. Thank you in advance.
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
void menu (void);
void open_accnt (void);
void deposit (void);
void withrawal (void);
void balance (void);
void close_accnt (void);
void exit (void);
struct new_accnt
{
char accnt_name [50];
char accnt_lname [50];
char type [50];
double cash;
};
int choice =0;
int open_a =0;
bool account=0;
double bal =0;
char close;
new_accnt w;
//------------------------------------------------------------------------------
void main (void)
{
menu();
clrscr();
}
//----------------------------------------------------------------------------------------
void menu (void)
{
clrscr();
cout << "\n W E L C O M E T O B A N K O F P A U T A N G \n\n\n";
cout << "\n _________MAIN MENU__________\n";
cout << "\n | [1] Open Account |";
cout << "\n | [2] Deposit Transaction |";
cout << "\n | [3] Withrawal Transaction |";
cout << "\n | [4] Balance Inquiry |";
cout << "\n | [5] Close Account |";
cout << "\n | [6] Exit |";
cout << "\n _____________________________";
cout << "\n\n Please Enter your Choice: "; cin >> choice;
if (choice == 1)
{
open_accnt();
menu();
}
elseif (choice == 2)
{
deposit();
menu();
}
elseif (choice == 3)
{
withrawal();
menu();
}
elseif (choice == 4)
{
balance();
menu();
}
elseif (choice == 5)
{
close_accnt();
menu();
}
elseif (choice == 6)
{
exit();
}
else
{
clrscr;
cout << "\n\n\n\n\n\n\t\t---> Please Enter Choice fron 1 to 6 Only <---";
cout << "\n\n\n\n\n\n\t\t Please Press Any Key To Contiue.....";
getch();
menu();
}
getch();
}
//------------------------------------------------------------------------------------------------------
void open_accnt (void)
{
clrscr();
if (open_a == 1)
{
cout << "\n\n\n\n\n\t\t Invalid! Account Already Existing!";
}
else
{
cout << "\n\t *****---------- O P E N A C C O U N T ----------*****";
cout << endl;
cout << "\n\n\tPlease Enter Your First Name: ";
gets (w.accnt_name);
cout << "\n\n\tPlease Enter Your Last Name: ";
gets (w.accnt_lname);
cout << "\n\n\tCurrent or Savings Account: ";
gets (w.type);
retry:
cout << "\n\n\tPlease Enter Initial Deposit: ";
cin >> w.cash;
if (w.cash<200)
{
cout << "\n\n\tSorry, Minimum Deposit allowed is 200";
getch();
goto retry;
}
cout << "\n\n\n\t\t\t\t Account Created!";
open_a = 1;
}
getch();
account=1;
bal = w.cash;
menu();
}
//------------------------------------------------------------------------------------------------------
void deposit (void)
{
clrscr();
if(open_a == 0)
{
cout << "\n\n\n\n\n\t\t\t\tPlease Open An Account First!";
}
else
{
cout << "\n\t *****---------- D E P O S I T T R A N S A C T I O N ----------*****";
cout << " ";
cout <<"\n\n\t\tAccount Type: "<< w.type;
double deposit_accnt=0;
cout << "\n\n\t\t Please Enter Amount To Deposit: ";
cin>> deposit_accnt;
bal = bal + deposit_accnt;
cout<<"\n\n\t\t\t New Balance is = "<< bal;
}
getch();
menu();
}
//------------------------------------------------------------------------------------------------------
void withrawal (void)
{
clrscr();
if(open_a == 0)
{
cout << "\n\n\n\n\n\t\t\t\tPlease Open An Account First!";
}
else
{
cout << "\n\t****------ W I T H R A W A L T R A N S A C T I O N -----****";
cout << " ";
cout << "\n\n\t\tAccount Type: "<< w.type;
double withraw=0;
cout << "\n\n\t\tPlease Enter Amount To Take Out: ";
cin >> withraw;
cout<<"\n\n\t Transaction Successful!";
bal = bal - withraw;
}
getch();
menu();
}
//---------------------------------------------------------------------
void balance (void)
{
clrscr();
if(open_a == 0)
{
cout << "\n\n\n\n\n\t\t\t\tPlease Open An Account First!";
}
else
{
cout << "\n\t *****---------- B A L A N C E I N Q U I R Y ----------*****";
cout << " ";
cout << "\n\n\n\t\t\t\tName: " << w.accnt_name;
cout << "\n\n\n\t\t\t\tYour Account: " << w.type;
cout << "\n\n\n\t\t\t\tYour Balance Is: "<< bal;
}
getch();
menu();
}
//-----------------------------------------------------------------------
void close_accnt (void)
{
clrscr();
if(open_a == 0)
{
cout << "\n\n\n\n\n\t\t\t\tPlease Open An Account First!";
}
else
{
cout << "\n\t *****---------- C L O S I N G A C C O U N T ----------*****";
cout << "\n\n\tYour Account Name:"<< w.accnt_name<<" "<<w.accnt_lname;
cout << "\n\n\tAccount Type: "<< w.type;
retrys:
cout << "\n\n\tDo You Want To Close Your Accont? [Y/N] ";
cin >> close;
if (close == 'y' || close == 'Y')
{
account=0;
cout << "\n\n\t\t\tAccount Closed!";
getch();
menu();
}
elseif (close == 'n' || close == 'N')
{
menu();
}
else
{
cout << "\n\n\tSorry Invalid Input";
getch();
goto retrys;
}
}
getch();
menu();
}
//-------------------------------------------------------------------------------------------
void exit (void)
{
cout << "\n\n\n\n\n\t\t Thank You and See You Soon....";
sleep(2);
exit(0);
}