i am new to c++ and currently faces some obstacles and hope that someone can help me to solve this problem. And below is my code :
At first, the user need to enter "account number" , "account holder name" and "deposit" and all the data will store into a text file which will automatically create. Then the user need to login with the correct "account number" and "account holder name" . But after login successfully, it will display all the accounts which the user created just now.
title of program : Bank Management System
Problem : - if create more than one account, then it will display all the accounts that have created at one time.
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std ;
void create_account ()
{ long long int acc_no ;
string name ;
double deposit ;
char choice ;
do{
system ("cls");
cout << "PLEASE CREATE YOUR ACCOUNT !" << endl ;
cout << "ENTER THE ACCOUNT NO : " ;
cin >> acc_no ;
cout <<"ENTER THE NAME OF THE ACCOUNT HOLDER : " ;
cin.ignore() ;
getline( cin, name ) ;
cout << "ENTER AMOUNT FOR DEPOSIT : RM " ;
cin >> deposit ;
ofstream outfile ("accounts.txt", ios::app) ;
outfile << endl << acc_no << " " << name << " " << deposit << endl ;
outfile.close() ;
cout << endl << endl ;
cout << "ACCOUNT SUCCESSFULLY CREATED !" << endl << endl ;
system ("pause") ;
do{
cout << "DO YOU WANT TO CONTINUE ? "<< endl ;
cout << "ENTER YOUR CHOICE ( Y OR N ): " ;
cin >> choice ;
}while (choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N' );
}while (choice == 'y' || choice == 'Y');
}
void view_account ()
{
ifstream infile("accounts.txt",ios :: in ) ;
string x , y , z ;
while (infile >> x >> y >> z )
{
cout << endl <<"***************************************************"
<< endl << "ACCOUNT NUMBER IS : " << x
<< endl << "ACCOUNT HOLDER NAME IS : " << y
<< endl << "BALANCE AMOUNT : RM " << z << endl
<< endl <<"***************************************************" ;
}
infile.close() ;
cout << endl << endl ;
system("pause");
}
void login()
{ string acc_no1, name1;
int offset ;
string line ;
ifstream infile ;
infile.open("accounts.txt");
cout << endl << endl ;
cout << "PLEASE LOGIN YOUR ACCOUNT ! " << endl ;
cout << "ENTER YOU ACCOUNT NO : " ;
cin >> acc_no1 ;
cout << "ENTER ACCOUNT HOLDER NAME : ";
cin.ignore() ;
getline ( cin , name1 ) ;
if (infile.is_open())
{
while(!infile.eof())
{
getline (infile,line);
if ( (offset = line.find(acc_no1,0)) != string::npos && ((offset = line.find(name1,0)) != string::npos) )
{
cout << "LOGIN SUCCESSFULLY" << endl ;
system("pause");
view_account ();
}
}
infile.close() ;
}else
cout << "" ;
system("cls") ;
cout << endl << "LOGIN FAILED !" << endl ;
system("pause");
}
int main ()
{
create_account () ;
login();
}