Reading data from Text file in series!

I need to create a program of bank transaction where I would write following information in 'trans.txt' file.

deposit 500
deposit 150
withdrawal 245
deposit 900

etc..

The program would then read the data from 'trans.txt' file and add all the values up. Also there will be count to see the number of transaction performed. The deposits will be added and withdrawals will be subtracted from base amount of $0.00

Is there a way where code would recognize either it is depositing or withdrawing money and appropriately add or subtract?

Is there any way to store the values in array?

I am new to the programming, so please help me!

Thanks,
Jay
Last edited on
If the code reads 'trans.txt' one line at a time into a string you can use the find method of the string class to discover if the line has 'deposit' or 'withdrawal' in it. You can then use substr to get the rest of the line (which will be the amount) and add or subtract accordingly.
Repeat until you have read the whole file.
See http://www.cplusplus.com/doc/tutorial/files.html for using files and
http://www.cplusplus.com/reference/string/ for the string class if you need info on either.
Topic archived. No new replies allowed.