View Single Post
  #6 (permalink)  
Old December 14th, 2004, 03:06 PM
davekw7x davekw7x is offline
Authorized User
Join Date: Feb 2004
Location: , , .
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts

Well, I think I understand you OK:

your program doesn't work the way you think it should.

My suggestions were to get you to look at what your program actually does:

accfile >> accs[1].accno
If the first line of your data file has

3 accounts
then this statements stores the number 3 in the account number field of account number 1. Why?????

Then you read the rest of the line

  getline (accfile, na);
This puts " accounts" into string na

Then this
Tries to calculate the integer value of the string, then does nothing with the result (The result is zero, by the way.)

Then you read the rest of the file. If each line has an account number and a name, you have read values into accs[0], accs[1], and accs[2]. If you put cout statements as I suggested, you can see whether the file data is what you think it is.

Now, after reading the accounts and performing a transaction, you close the file, then open the same file for writing and you write out the account information. Note that you did not write the first line "3 accounts". So the next time you try to use this as an input file, the program fails. (When you open a file for writing it destroys the previous contents of the file, so you must re-create the entire contents for it.)

Now, If I have misunderstood you, maybe you can tell me what you really mean.


Reply With Quote