Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-11-2000, 10:38 AM   #1
Member (8 bit)
 
TechTeach's Avatar
 
Join Date: Jul 1999
Posts: 141
Angry

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 {
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]
TechTeach is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:40 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2