Debt Loans | Personal Loans | Loans | Cheap Magazines | Adverse Credit Remortgage
C++ parallel arrays [Archive] - PCMech Forums

PDA

View Full Version : C++ parallel arrays


TechTeach
11-11-2000, 10:38 AM
I'm working on a C++ program for a class. We are learning arrays. We have already learned functions and files.

I'm reading information from a file into four parallel arrays. The file is set up like this. There are 24 acct's.

acct #, name, start balance, start check #|
109230, Bob Brown, 120.00, 134,\n
234509, Sadie Hawkins, 300.55, 239,\n
(The spacing that I used to type the post doesn't show once it is posted. Each line in the file contains an acct#, a name, a start balance, and a check #.)

I successfully read all of the information into the arrays.
But something is going on with the accountNumber array. The information is read in correctly. But when I output the accountNumber array the first 15 numbers are incorrect and accountNumber[15] to accountNumber[23] are correct.

In problem solving this I found that right after I increment index the account number array is all zeros. Before this the array is holding the correct information.

This is the function definition that reads the data into the parallel arrays.

void ReadIntoParallelArray(ifstream& inFile,
int accountNumber[],
stringType name[],
float balance[],
int checkNumber[],
int& numberOfAccounts,
int maxSizeOfArray)
{
int index= 0;
int tempAccount =0;
stringType tempName;
float tempBalance;
int tempCheckNumber;

inFile >> tempAccount;

while (!inFile.eof() && index< maxSizeOfArray)
{
accountNumber[index] = tempAccount;

cout << account[index] << " ";
//cout for problem solving
//used drag and drop to move it
//through the loop with each
//run.

inFile.ignore(1);

inFile.getline(name, STRING_LENGTH + 1);

inFile >> balance[index];

inFile >> checkNumber[index];

index ++;
// accountNumber array becomes all zeros

inFile >> tempAccount;

}

/* was using this loop to problem solve
for (int count=0; count<index; count++)
{
cout<< accountNumber[count]<< " ";
} */


numberOfAccounts = index;
}

If you have any suggestions... please e-mail me at lorax246@yahoo.com. I'm using Visual C++ 6.0 to compile.

[Edited by TechTeach on 11-11-2000 at 12:42 PM]