I need to take a number from an ifstream inputFile, add or subtract (depending on what the user wants), do that operation with the number and then write it back into the file. It should end up looking like this in the file:
11/01/2017
Initial Deposit
1000
1000
11/14/2017
Titan Bookstore Online
-245.67
754.33
It has to work with more than 2 transactions. I am able to write the initial deposit and gather the date, transaction name, and amount but not the new total. My code so far is:
That's a good start, but you'll want to format that as code to make it more legible.
(The shortcut for code is to highlight the text and then click the <> button to the right.)
Just as my initial thoughts based on your project description, what you want to do is store your initial deposit into a float in a manner such as B >> number;, do your math, then output it as the final amount like B << number;. Upon looking at your code it seems that you're underutilizing the fstream, or using fstream erroneously when you want to be using ifstream for inB and ofstream for outB.
UPTADE 1: I've been testing your code myself and the first big issue I encountered was that your stringstream ss never got initialized. The first thing you should do with objects in C/C++ is either call a constructor on them or assign them something. ss << accountNumber << ".dat"; may include an assignment, but the compiler doesn't know that. Scratch what I said about stringstream. I'm learning too.