Can anyone guide me how to solve for the login problem..i think is the read file problem..
I try many ways but can't.
here the code:

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <windows.h>

using namespace std;

class bankAccount
{
      private:
              string name, loginName,loginName1;
              float IDnum;
              int  password,password1;
              char ans;
              
      protected:
                float balance;
                float balance1;
                double annualInterestRate;
                double monthlyInterestRate, monthlyInterest;
                double totalAmount;
                double thismonthDeposit;
                double thismonthWithdrawal;
                double MonthlyServiceCharge;
                double totalWithdrawAmount,totalDepositAmount;
                double totalWithdrawal, totalDeposit;
                int numberOfDeposit;
                int numberOfWithdrawal;
                friend class savingAccount;
                
                
                
      public:
             void loadsavedData();
             void registerProfile();
            
             bankAccount()
             {
                          float balance = 0;
                          double annualInterestRate;
                          }
                          
                    
             void header1()
              {
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13); //replace the 0 with a number for the color you want
                   cout<<"\n\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
		           cout<<"\n\n\t\t~          Welcome to          ~";
                   cout<<"\n\n\t\t~      SUJU Banking System     ~";
                   cout<<"\n\n\t\t~                              ~";
		           cout<<"\n\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<endl; 
                   }
             
              void header2()
             {
                  cout<<"             W     E     L     C     O     M     E"<<endl<<endl;
                  cout<<"              W     E     L     C     O     M     E"<<endl<<endl;
                  cout<<"               W     E     L     C     O     M     E"<<endl<<endl;
                  cout<<"             W     E     L     C     O     M     E"<<endl<<endl;
                  cout<<"            W     E     L     C     O     M     E"<<endl<<endl;
                  }
                  
             void header3()
             {
                   cout <<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
                   cout <<"\t\t@                                             @"<<endl;
                   cout <<"\t\t@               ~ Thank you ~                 @"<<endl;
                   cout <<"\t\t@             ~ See you again ~               @"<<endl;
                   cout <<"\t\t@                                             @"<<endl;
		           cout <<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
                  }
                  
             void footer1()
             {
                  cout<<"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-"<<endl;
                  cout<<"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_"<<endl;
                  }
                  
             void footer2()
             {
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
                  cout<<"###############################################################################"<<endl;
                  cout<<"###############################################################################"<<endl;
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                  }
                          
                          
                   
             float calcInt()
             {
                   
                  annualInterestRate = 0.5;
                  
                  monthlyInterestRate = (annualInterestRate/12);
                  
	              monthlyInterest = balance * monthlyInterestRate;
	              
	              balance = balance + monthlyInterest;
	              
                   }
                   
             void withdraw();
             void deposit();
             
                  
             void registeration()
             {
                  fstream myfile;
                  
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
                  cout <<"\tEnter 'Q' to return to quit."<<endl;
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                  cout<<"\tEnter desired login ID: ";
                  getline(cin, loginName);
                  cout<<endl;
                  
                  
                  if(loginName == "q" || loginName == "Q")
                  {
                               system("cls");
                               SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
                               header3();
                               return ;
	              }
	
                  cout<<"\tEnter desired password(in digit): ";
                  cin>>password;
                  cout<<endl;
                  
                  if (password >= 10000)
                               {        
                                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
                                        cout <<" \t\t\t------------------------------"<<endl;
                                        cout <<"\t\t\t [Password secure level : Strong]"<<endl;
                                        cout <<"\t\t\t ------------------------------"<<endl;
                                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                                        }
                  if (password < 10000)
                               {       
                                       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                                       cout <<"\t\t\t  ----------------------------"<<endl;
                                       cout<<" \t\t\t [Password secure level : Weak]"<<endl;
                                       cout <<"\t\t\t  ----------------------------"<<endl;
                                       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                                       cout<<"\tPlease insert a new 5-digits password : ";
                                       cin>> password ;
                                       cout<<"\tYour password has been changed !! " <<endl;
                                       }       
                                       
                                       myfile.open("BankData.txt", ios::out | ios::app);
	                                   if (myfile.is_open())
	                                   {
		                               myfile<<loginName <<endl;
		                               myfile<<password <<endl;
		
		                               
		                               myfile.close();
	                                }
	                                   
	                                   reminder();
	                                   
	                                   cout<<endl;
	                                      
                                       registerProfile();  
                                       
                                       system("cls");
                  
                  }
                  
                  
                   void reminder()
                   {
                      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
                     cout<<"\tRemember your loginID and password"<<endl;
                     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
                     cout<<"\tLoginID: "<<loginName<<endl;
                     cout<<"\tPassword: "<<password<<endl;
                    
                                      }
                  
             void monthlyProc()
             {
                  calcInt();
                  balance -= MonthlyServiceCharge;
                  
                  cout<<"\tYour balance now is: "<<balance<<endl;
                  
                  numberOfDeposit = 0;
                  numberOfWithdrawal = 0;
                  MonthlyServiceCharge = 0;
                  
                  }
                  
              void saveSave();
              void loadLoad();
                   
              void login();
              
	                 
                       
              void menu()
              {
                   char functions;
                   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
                   cout<<"\t\t\t*****************************"<<endl;
                   cout<<"\t\t\t*         Menu Page         *"<<endl;
                   cout<<"\t\t\t*****************************"<<endl<<endl;
                   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
                   cout<<"\t\t###########################################"<<endl;
                   cout<<"\t\t#  Please select the following functions  #"<<endl;
		           cout<<"\t\t#  1. Withdrawal                          #"<<endl;
		           cout<<"\t\t#  2. Deposit                             #"<<endl;
		           cout<<"\t\t#  3. Check Balance                       #"<<endl;
		           cout<<"\t\t#  4. Exit                                #"<<endl;
		           cout<<"\t\t###########################################"<<endl;
		           cout<<endl;
		           SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
		           cout<<"\tSelect: ";
		           cin>>functions;
		           
		           switch(functions)
		           {
                     case ('1'): system("cls");
                                 withdraw();
                                 break;
                                 
                     case ('2'): system("cls");
                                 deposit();
                                 break;
                                 
                     case ('3'): system("cls");
                                 displayStatistic();
                                 break;
                                 
                     case ('4'): system("cls");
                               SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
                               header3();
		                       system("Pause");
		                       return ;
                                 
                     default:    cout<<"\n\n\tInvalid choice!!\n\n";
                                 cout<<"\tSystem exiting now....."<<endl;
                     }
                                    
                    system("cls");
                    displayStatistic();
                   
                   }
                   
                   
             void displayStatistic();
             
             
                   

      };
      
void bankAccount :: registerProfile()
{
     
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
     cout<<"\tYou are about to register an account"<<endl;
     cout<<"\tEnter your name: ";
     cin>>name;
     cout<<endl;
                  
     cout<<"\tEnter your identity card number: ";
     cin>>IDnum;
     cout<<endl;
     
     cout<<"\tEnter amount you want to deposit: $ ";
     cin>>balance1;
     balance = balance1;
     cout<<"\tRegisteration complete!!"<<endl;
     cout<<"\tThanks for choosing SUJU Bank"<<endl;
     
     numberOfDeposit = 0;
     numberOfWithdrawal = 0;
     
     saveSave();
     login();
     
     
     
}
      
class savingAccount:public bankAccount
{
      
      public:
             char status;
             
             void withdraw(float balance)
             {
                  if(balance < 25)
                  {
                                status = '0';
                                }
                                
                  if(balance > 25)
                  {
                             status = '1';
                             }
                             
                  }
             
             void deposit(float balance)
             {
                  if(balance < 25)
                  {
                                status = '0';
                                }
                                
                  if(balance > 25)
                  {
                             status = '1';
                             }
                             
                  }
                  
             void monthlyProc(int numberOfWithdrawal , float balance)
             {
                  if(numberOfWithdrawal < 4)
                  {
                       MonthlyServiceCharge = 0;
                                        
                                        }
                  else if(numberOfWithdrawal > 4)
                  {
                       MonthlyServiceCharge = 1;
                       MonthlyServiceCharge += MonthlyServiceCharge ;
                       
                       if(balance < 25)
                       {
                                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                                  status = '0';                                
                                  cout<<"\tInactive account"<<endl;
                                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                                  }
                       }
                  }
           
             
      };
      
void bankAccount::withdraw()
{
     int count1 = 0;
     totalWithdrawal = 0;
     totalDeposit = 0;
     
     savingAccount *SA = new savingAccount;
     SA -> withdraw(balance);
     
     if(SA -> status == '1')
     {
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
         cout<<"\t\t\t*****************************"<<endl;
         cout<<"\t\t\t*      Withdrawal Page      *"<<endl;
         cout<<"\t\t\t*****************************"<<endl<<endl;
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
         cout<<"\tEnter the amount you want to withdraw: ";
         cin>>totalWithdrawAmount;
         totalWithdrawal = totalWithdrawAmount;
         balance -= totalWithdrawAmount ;
         thismonthWithdrawal +=  totalWithdrawal;

         count1++;
         numberOfWithdrawal = count1 ;
         
         cout<<"\tNumber of withdrawal made: "<<count1<<endl;
         cout<<"\tBalance: "<<balance<<endl;
         
                          }
                          
      else if(SA -> status == '0')
      {
     
      
      deposit();
      }
     system("pause");
     }
     
void bankAccount::deposit()
{
     savingAccount *SA = new savingAccount;
     SA -> withdraw(balance);
     
     int count2 = 0;
     totalDeposit = 0;
     totalWithdrawal = 0;
     if(SA -> status == '1')
     {     
           cout<<"\t\t\t*****************************"<<endl;
           cout<<"\t\t\t*      Deposit page         *"  <<endl;
           cout<<"\t\t\t*****************************"<<endl<<endl;
           cout<<"\tEnter the amount you want to deposit: ";
           cin>>totalDepositAmount;
           totalDeposit = totalDepositAmount;
           balance += totalDepositAmount;
           thismonthDeposit += totalDeposit  ;
           
           count2++;
           numberOfDeposit = count2;
           
           
           cout<<"\tNumber of deposit made: "<<count2<<endl;
           cout<<"\tBalance: "<<balance<<endl;
         
                         }
                         
      else if(SA -> status == '0')
      {
      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
      cout<<"\tInactive account!!"<<endl;
      cout<<"\tAccount had been suspended~"<<endl;
      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
      cout<<"\tPlease make sure that your balance is over $25 to access"<<endl;
      cout<<"\tEnter 1 the amount you want to deposit: "<<endl;
      cout<<"\tEnter 0 to quit"<<endl;
      cout<<"\tSelect: ";
      int answer;
      cin>>answer;
      if(answer == 0)
      {
                totalDeposit = 0;
                totalWithdrawal = 0;
                numberOfDeposit = 0;
                numberOfWithdrawal = 0;
                MonthlyServiceCharge = 0;
                
                header3();
                system("cls");
                return ;
                }
      else if(answer == 1)
      {
           totalDeposit = 0;
           totalWithdrawal = 0;
           numberOfDeposit = 0;
           numberOfWithdrawal = 0;
           MonthlyServiceCharge = 0;
           cout<<"\tEnter the amount to deposit: ";
           cin>>totalDepositAmount;
           totalDeposit = totalDepositAmount;
           balance += totalDepositAmount;
           thismonthDeposit += totalDeposit  ;
           
           count2++;
           numberOfDeposit = count2;
           
           
           cout<<"\tNumber of deposit made: "<<count2<<endl;
           cout<<"\tBalance: "<<balance<<endl;
            cin.clear();
           cin.ignore();
           getchar();
           system("cls");
           menu();
           
           }
      
      }
       cin.clear();
       cin.ignore();
       getchar();
     }
     
void bankAccount::displayStatistic()
     {
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);                        
            cout<<"\t\t --------------------------------------------"<<endl;
            cout<<"\t\t->Displaying account statistic for this month~|"<<endl;
            cout<<"\t\t->Beginning balance: "<<balance1<<endl;
            cout<<"\t\t->Total amount of deposit: "<<totalDeposit<<endl;
            cout<<"\t\t->Total amount of withdrawal: "<<totalWithdrawal<<endl;
            cout<<"\t\t->Number of deposit made: "<<numberOfDeposit<<endl;
            cout<<"\t\t->Number of withdrawal made: "<<numberOfWithdrawal<<endl;
            cout<<"\t\t->Total monthly service charge: "<<MonthlyServiceCharge<<endl;
            cout<<"\t\t->Ending balance: "<<balance<<endl;
            cout<<"\t\t --------------------------------------------"<<endl;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            
           cin.clear();
           cin.ignore();
           getchar();
           
                  }
                  
void bankAccount :: login()
{
     string loginName = "" , password = "";
     string loginName1 = "" , password1 = "";
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
     cout<<"\t\t\t*****************************"<<endl;
     cout<<"\t\t\t*         Login Page        *"<<endl;
     cout<<"\t\t\t*                           *"<<endl;
     cout<<"\t\t\t*****************************"<<endl<<endl;
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                      
     cout<<"\tPlease enter 1 login"<<endl;
     cout<<"\tEnter 0 to exit"<<endl;
     cout<<"\tSelect: ";
	                  
     int answers;
     cin>>answers;
	                  
     footer2();
	  
     system("cls");
                                    
     if(answers == 1)
     {
        cout.flush();
        cout<<"\tLogin ID: ";
        getline(cin, loginName1);
        cin.ignore();
        
     
        cout<<endl;
        cout<<"\tPassword: ";
        getline(cin, password1);
        cin.ignore();
                      
     ifstream myfile("BankData.txt",ios::in);
     if (myfile.is_open())
     {
                                            
        while (!myfile.eof() )
        {
                             
                             myfile>>loginName;
                             myfile>>password;
			
			
     if(loginName == loginName1 && password == password1)
     {   
                       
         menu();
         break;
                      		
	    }
				        
     else if(loginName != loginName1 && password != password1)
     {
                            
        cout<<"\tUnregistered ID or you have enter a wrong password !"<<endl;
        system("pause");
        login();   
       }
			    
       myfile.close();
                                }
       
       }
                      
     else if(answers == 0)
     {
          return ;
          }
                      
                          
             
     }            
}

void bankAccount :: saveSave()
{
     ofstream myfile;
     myfile.open("savedData.txt", ios::out);
     if(myfile.is_open())
     {
       myfile<<name<<endl;
       myfile<<IDnum<<endl;
       myfile<<balance<<endl;
       myfile<<numberOfDeposit<<endl;
       myfile<<numberOfWithdrawal<<endl;
       
       myfile.close();
       }
     
}
void bankAccount :: loadsavedData()
{
    ifstream myfile("savedData.txt");
     if(myfile.is_open())
     {
       while(!myfile.eof())
       {
             myfile>>name;
             myfile>>IDnum;
             myfile>>numberOfDeposit;
             myfile>>numberOfWithdrawal;
             myfile.close(); 
                          
                           }
       }
       else
       {
           cout<<"File does not exist"<<endl;
           cin.clear();
           cin.ignore();
           getchar();
           return ;
                  }
     
}

int main()
{
    int selections;
    
    bankAccount *BA = new bankAccount;
    savingAccount *SA = new savingAccount;
    
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
    BA -> footer1();
    BA -> header1();
    BA -> header2();
    BA -> footer1();
    
    cout<<endl;
    cout<<endl;
    
    BA -> footer2();

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
    cout<<"\tPlease choose one of the below options"<<endl;
    cout<<"\t1. Account Registration"<<endl;
    cout<<"\t2. User Login"<<endl;
    cout<<"\t3. Exit"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    BA -> footer2();
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<endl;
    cout<<"\tSelection: ";
    cin>>selections;
    system("cls");
    cin.ignore();
    BA -> footer2();
    
    if(selections == 1)
    {
                  BA -> registeration();
                  
                  }
                  
    else if(selections == 2)
    {
                 BA -> login();
                 }
                 
    else if(selections == 3)
    {
                 exit(0);
         }
                 
    
    
    cin.clear();
    cin.ignore();
    getchar();
    return 0;
    }

someone please help me out =(

ifstream myfile("BankData.txt");
     
     if (myfile.is_open())
     {
                                            
     while (!myfile.eof())
     {
                             
       myfile>>loginName;
       myfile>>password;
			
			
     if(loginName == loginName1 && password == password1)
     {                  
         menu();
         break;             		
	    }
				        
     else 
     {
                            
        cout<<"\tUnregistered ID or you have enter a wrong password !"<<endl;
           
           cin.clear();
           cin.ignore();
           getchar();
           return ;  
       }
			    
       myfile.close();
                                }
       
       }

this part wrong is it? how can i correct it?

really no one can help?

The block of code you just provided us appears that it would work as desired. Use of eof() is discouraged, but I don't see it as a major problem here.

You originally threw over 600 lines of code at us with a "Help me it doesn't work" type of request.

A better way to pose your question would be to tell us what part specifically doesn't work, what output you expect, and what output you are currently getting. Also, since this problem deals with file i/o, of course, we'll need to see a sample of your file.

The block of code you just provided us appears that it would work as desired. Use of eof() is discouraged, but I don't see it as a major problem here.

You originally threw over 600 lines of code at us with a "Help me it doesn't work" type of request.

A better way to pose your question would be to tell us what part specifically doesn't work, what output you expect, and what output you are currently getting. Also, since this problem deals with file i/o, of course, we'll need to see a sample of your file.

ok well..i think this part got problem..

ifstream BanKing;
     BanKing.open("BankData.txt");
     
                                            
     while (!BanKing.eof())
     {
                             
       BanKing>>loginName;
       BanKing>>password;
			
			
     if(loginName == loginName1 && password == password1)
     {                  
         menu();
         break;             		
	    }
				        
     else 
     {
                            
        cout<<"\tUnregistered ID or you have enter a wrong password !"<<endl;
           
           cin.clear();
           cin.ignore();
           getchar();
           return ;  
       }
			    
       BanKing.close();
                                }
       
       }

i got a function that get the input of login id and password and store in a file,

void registeration()
             {
                  
                  fstream BanKing;
                  
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
                  cout <<"\tEnter 'Q' to return to quit."<<endl;
                  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                  cout<<"\tEnter desired login ID: ";
                  getline(cin, loginName);
                  cout<<endl;
                  
                  
                  if(loginName == "q" || loginName == "Q")
                  {
                               system("cls");
                               SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
                               header3();
                               return ;
	              }
	
                  cout<<"\tEnter desired password(in digit): ";
                  cin>>password;
                  cout<<endl;
                  
                  if (password >= 10000)
                               {        
                                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
                                        cout <<" \t\t\t------------------------------"<<endl;
                                        cout <<"\t\t\t [Password secure level : Strong]"<<endl;
                                        cout <<"\t\t\t ------------------------------"<<endl;
                                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                                        }
                  if (password < 10000)
                               {       
                                       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                                       cout <<"\t\t\t  ----------------------------"<<endl;
                                       cout<<" \t\t\t [Password secure level : Weak]"<<endl;
                                       cout <<"\t\t\t  ----------------------------"<<endl;
                                       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                                       cout<<"\tPlease insert a new 5-digits password : ";
                                       cin>> password ;
                                       cout<<"\tYour password has been changed !! " <<endl;
                                       }       
                                       
                                       BanKing.open("BankData.txt", ios::out);
	                                   if (BanKing.is_open())
	                                   
		                               BanKing<<loginName <<"\t";
		                               BanKing<<password <<"\t";
		
                                       BanKing.put('\n');
		                               BanKing.close();
	                                
	                                   
	                                   reminder();
	                                   
	                                   cout<<endl;
	                                      
                                       registerProfile();  
                                       
                                       system("cls");
                               }

then i use a function that can login by compare the login id and password inserted..

text file:
BankData.txt
hao 12345

savedData.txt
1
1
10000
0
0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.