View Single Post
  #4 (permalink)  
Old December 12th, 2004, 04:45 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Location: , , .
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's how I would think about debuging the program.

First of all, since your program changes the "accounts.dat" file that means that you have to re-create it again every time you run the program. For the time being, make a different output file.

Now, as you read each thing into your program, show what the program actually sees by using cout.

For example:

Code:
accfile >> accs[1].accno;
  cout << "Debug: accs[1].accno = " << accs[1].accno<< endl;
  //getline (accfile, ucty);
  getline (accfile, na);
  cout << "Debug: na = " << na << endl;
  atoi(na.c_str());  
  cout <<"Debug: This was from first line: <" << na << ">" << endl;

  do   //this does counting of accounts but I want to replace with stuff above
    {  //where reading from first line says how many accounts are there
      cout << "Top of loop: nRead = " << nRead << endl;
    accfile >> accs[nRead].accno >> accs[nRead].balance;

    cout << "Debug: accs[" << nRead << "].accno = " << accs[nRead].accno << endl;
    cout << "Debug: accs[" << nRead << "].balance = " << accs[nRead].balance << endl;
Get the point? Print out everything until you are sure what the program sees. Then you can delete or comment out the extra cout statements.

By the way, why did you do this for the very first read:
Code:
  accfile >> accs[1].accno;
How about this:

Code:
  atoi(na.c_str());
This calculates something, but doesn't store the value in a variable, so what's supposed to happen.

Regards,

Dave
Reply With Quote