jeudi 3 septembre 2020

Withdraw , deposit, delete problem in c++ (fstream) [closed]

i write a program for banking in c++ it is a sample program which has 2 options

1st: option is for create an account through which i am taking some information like account_no, the name of customer and the balance and store it in a file name (Accounts.txt)

2nd: option is for login through which the user will have to give the account_no and it will show the name and the balance of that account number:

in the 2nd option it has 3 other options

1st: option is for deposit. 2nd: option is for withdraw. 3rd: option is for delete an account.

but i am stuck in these 3 option For deposit and withdraw i write a code but it is not working and for the delete account option i don't have any idea to how to do that.

Here is my code if any one can help Me

#include<iostream>
#include<fstream>
Using namespace std;
{
string name,account_no,account_no_check,ballance;
cout<<"\tCreate Account\n\n\t";
cout<<"\tEnter Customer Account Number: ";
cin>>account_no_check;              
fstream create("Accounts.txt",ios::app|ios::in|ios::out); 
while(std::getline(create,name)&&std::getline(create,account_no)&&std::getline(create,ballance))                
{
if(account_no_check==account_no)
{
    system("cls");
    cout<<account_no;
    cout<<name;
    cout<<ballance;
    string choose;
    create.close();
    cout<<"\n\n\n\tEnter 1 For Deposite Money\n\tEnter 2 For Withdraw Money";
    cin>>choose;
    if(choose=="1")
    {
        float withdraw,Money;
        cout<<"Amount to withdraw: ";
        cin>>withdraw;
        Money=std::stof(ballance);
        Money=withdraw+Money;
        fstream temp("temp.txt",ios::binary|ios::in|ios::out);
        temp<<account_no<<'\n';
        temp<<name<<'\n';
        temp<<Money<<'\n';
        temp<<'\n';
        temp.close();
        create.open("Accounts.txt",ios::binary|ios::in|ios::out);
        while(std::getline(create,name)&&std::getline(create,account_no)&&std::getline(create,ballance))
        {
            temp<<account_no<<'\n';
            temp<<name<<'\n';
            temp<<ballance<<'\n';
            temp<<'\n';
        }
        remove("Accounts.txt");
        rename("temp.txt","Account.txt");
        return 0;   
    }
    else
    {
        if(choose=="2")
        {
            float deposite,Money;
            cout<<"amount: ";
            cin>>deposite;
            Money=std::stof(ballance);
            Money=Money-deposite;
            fstream temp("temp.txt",ios::binary|ios::in|ios::out);
            temp<<account_no<<'\n';
            temp<<name<<'\n';
            temp<<Money<<'\n';
            temp<<'\n';
            temp.close();
            create.open("Accounts.txt",ios::binary|ios::in|ios::out);
            while(std::getline(create,name)&&std::getline(create,account_no)&&std::getline(create,ballance))
            {
                temp<<account_no<<'\n';
                temp<<name<<'\n';
                temp<<ballance<<'\n';
                temp<<'\n';
            }
            remove("Accounts.txt");
            rename("temp.txt","Account.txt");
            return 0;
        }
        else
        {
            if(choose=="3")
            {
                cout<<"Delete Account";
            }
        }
else
{
    cout<<"incorrect name or password";
    return 0;
}
}
}

Aucun commentaire:

Enregistrer un commentaire