#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
constint ARRAY_SIZE = 1000; // Array size
double accountNumbers[ARRAY_SIZE]; // Array with 1000 elements
double accountBalances[ARRAY_SIZE]; // Loop counter variable
int count; // Input file stream object
ifstream inputFile;
// Open the file.
inputFile.open("FinalNumbers.txt");
// Read the numbers from the file into the array
while (count < ARRAY_SIZE && inputFile >> accountNumbers[count] >> accountBalances[count] ) {
count++;
}
inputFile.close();
// Display the read data
cout << "The bank account numbers are: ";
for (int count = 0; count < ARRAY_SIZE; count++) {
cout << accountNumbers[count] << "\n" << accountBalances[count] << " " << endl;
}
}
The code is printing out random numbers for first 20 or so numbers then carries on to print the right data skipping the last 20 or so numbers because the array runs out of space.
What I am aiming to do is make sure I have all the data stored properly then store the account numbers in ascending order with the proper balance paired to the account number...
Line 11: What do you think the initial value of count is? Hint: It's an uninitialized variable. It contains garbage.
Line 18: You're reading into a random place in the array because count contains garbage.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.