Hello,
I am having trouble with finding the running total in a .txt file.
I am asked to add up all the numbers for a specific category (like candy) and display total sale.
It doesn't look like your reading the file correctly. Plus, you're not increasing costs at all. The following worked in the program I tinkered with to get your code working.
Of course, you'll have to cout only the value of the item's total cost, that the user asks for.
Why did you use a C-string for item? The OP appears to be using std::string so if you're going to give the whole solution you should have at least stuck with the std::strings. Then you wouldn't have needed things like strcmp().
Also since you did use a C-string for item you should never use the extraction operator>> to extract the string unless you limit the number of characters that will be retrieved by using setw() before the string extraction. Never ever use a function that doesn't limit the number of characters that will be retrieved when working with C-strings.
Lastly you don't need to call the file close() function in this program. You're using C++ streams and since the stream goes out of scope on the next line (the end of the function) the class destructor will properly close() the file. Plus the fact that that close(), if you insist on using it, should be within the else block, not after it because if that else doesn't execute there is no need in trying to close an unopened file.