I am constructing a program that is basically a bank app. I know how to read in NEW "accounts" into a fstream file but the second option is to enter transactions into an EXISTING account. So far I was able to verify that the account (file) exists, but every time I try and just add data to the existing data, it ends up all mixed up and not at all what I want. I've tried fstream::app but I don't think I'm using it correctly. The following code is what I currently have but I've tried different ways also. (Sorry code is long)
//variables
int accountNumber;
string date, description;
float ammount;
string suffix=".dat";
and it actually fixed my problem. I don't understand why. But here is the full instructions for what I was trying to accomplish: :
If the user selects B., request the Account Number, Date, Description, and Amount from the user. Open the file with the file name “xxx.dat” where xxx is the Account Number requested from the user. If the file does not open, alert the user and return to the menu. The file should be opened in read/write mode and set to append data so as to not overwrite existing data. Read the last line in the file, which should be the balance of the account the last time a transaction was added. Write the Date, Description, Amount, and calculated new balance, each of these four data elements on a separate line in the file. The calculated new balance can be found from the balance read from the file plus/minus the Amount. Close the file. Return to the menu. As an example, when step 3 is complete, the file might look like: