i need to make a c++ console based program for a banking system using files. i implemented some code but having difficulty with withdrawing money from the account, checking balance, transferring funds and viewing transaction.

For withdrawing funds i implemented the following code but it doesn't seem to work properly. (To withdraw i need to ask the user to enter a name and from that i need to search the file from that right?)

Thank you very much in advance. Been stuck with this for a long time:(

void withdraw(){ 
    int accountNo; 
    string name,_name; 
    double amount,withdrawal; 
    string answer; 
    string line = ""; 
    cout<<"**Withdraw Cash**"<<endl; 
    ifstream cashfile("cashfile.txt"); 
    cout<<"Please Enter account Number:"<<endl; 
    cout<<"Please Enter Name"<<endl; 
    cout<<"Please Enter amount to withdraw Rs:"; 
    while (getline(cashfile,line)) { 
        stringstream pop(line); 
        amount = ::total - withdrawal; 
        ofstream cashfile; 
        cashfile.open("cashfile.txt",ios_base::trunc); //Discard the file’s contents 
        cashfile<<accountNo<<" "<<name<<" "<<amount<<" "<<endl; 
        cout<<"Amount withdrawal Successful"<<endl; 
        cout<<"Balance is Rs" << amount <<endl; 

This isn't really C++ (object oriented) code. What are your classes? What are the member variables they contain? What are the methods to get/set their data values? It is time you went back to the text book...

Not sure what lesson your instructor is trying to teach here, but this seems like a good opportunity to learn about Object Oriented Programming.

  • I'd start with a class("Account"). This would have properties for Account Number, Account Type, and Amount. The functions for deposit and withdrawal would be here.

  • Also a class("Customer"). This would have properties for Name, Address(another class), and a collection of accounts. A function for transferring between accounts

  • A class("Bank"). This would have properties for Name, Address and a collection of Customers

This might look and sound like a lot of work. However, you will quickly see how compartmentalizing your code like this makes things much easier to understaqnd what's going on.

commented: hi thank you for your reply. can i message you personally i really need some help on this PLEASE.. +0