Code:
#include <iostream>
#include <conio.h>
#include <windows.h>
void newAccount();
void Inquiry();
void Deposit();
void Withdraw();
void List();
int exitProgram();
void menu();
using namespace std;
string name[10];
int accountID[10], newAccountID;
int pin[10], newPIN;
double balance[10];
double amountDeposited=0.0;
int counter =0;
int main(){
system ("cls");
menu();
getch();
return 0;
}
void menu(){
char answer;
system("cls");
cout<<"\t\tWelcome to World Bank, Insert your Card in ATMmachine\n";
cout<<"\n";
cout<<"\t\t\tHello,Please enter your user name:\t\n";
cout<<"\n";
cout<<"[N]*New Account \n";
cout<<"[D]*Deposit \n";
cout<<"[I]*Inquiry \n";
cout<<"[W]*Withdraw \n";
cout<<"[L]*List all accounts\n";
cout<<"[E]*Exit Program \n";
cout<<"\nPlease Select : ";
cin>> answer;
if (answer == 'n' || answer == 'N'){
newAccount();
}else if (answer == 'd' || answer == 'D'){
Deposit();
}else if (answer == 'I' || answer == 'i'){
Inquiry();
}else if (answer == 'w' || answer == 'W'){
Withdraw();
}else if (answer == 'e' || answer == 'E'){
exitProgram();
}else if (answer == 'l' || answer == 'L'){
List();
}else{
cout <<"Invalid";
}
}
void newAccount(){
system ("cls");
cout<<"\nAccount ID : ";
cin>>accountID[counter];
cout<<"PIN : ";
cin>>pin[counter];
cout<<"Initial Deposit : ";
cin>>amountDeposited;
balance[counter] = balance[counter] + amountDeposited;
counter++;
menu();
}
void Deposit(){
system("cls");
cout<<"\nAccount ID : ";
cin>>newAccountID;
for (int y=0; y<counter; y++){
if (newAccountID == accountID[y]){
cout<<"PIN : ";
cin>>newPIN;
if (newPIN == pin[y]){
cout<<"How much to be deposited ? ";
cin>>amountDeposited;
balance[y] = balance[y] + amountDeposited;
cout<<"Your current balance is : "<<balance[y];
cout<<"\n Press any key to continue...";
getch();
}else{
cout <<"Invalid\n";
getch();
Deposit();
}
}
}
menu();
}
void Inquiry(){
system("cls");
cout<<"\nAccount ID : ";
cin>>newAccountID;
cout<<"PIN : ";
cin>>newPIN;
if (newAccountID == accountID[counter] && pin[counter] == newPIN){
cout<<"Your current balance is : " << balance;
}else{
cout<<"Invalid account, Press Enter to continue \n";
getch();
Inquiry();
}
getch();
menu();
}
void Withdraw(){
system("cls");
int amount;
cout<<"Account ID :";
cin >>newAccountID;
cout<<"PIN :";
cin>>newPIN;
if (newAccountID == accountID[counter] && pin[counter] == newPIN){
cout<<"Enter Amount :";
cin >>amount;
if (amount > balance[counter]){
cout<<"Insuficient Balance \n";
cout<<"Please enter a valid amount";
getch();
Withdraw();
}else{
cout<<"Processing....\n\n";
balance[counter] = balance[counter] - amount;
cout<<"Press Enter to continue";
}
}else{
cout << "Invalid account, Press Enter to continue \n";
getch();
Withdraw();
}
getch();
menu();
}
void List(){
system("cls");
cout<<"AccountID\t"<<"PIN"<<"\t"<<"Balance"<<"\n";
for (int x=0; x<counter; x++){
cout << accountID[x]<< "\t"<<"\t";
cout << pin[x]<<"\t";
cout << balance[x];
cout << "\n";
}
getch();
menu();
}
int exitProgram(){
cout << "\n\n \t\t thankyooooou! :) ";
return 0;
}
Comment