First check the value of numOfCustomers after reading the file, use a debugger or add a cout message.
When I tried it, the value was zero. So something is going wrong in the readFile() function.
A quick glance at the data:
and then at the file input statement shows a mismatch. There is nothing in the file to be read into the variable
cust[x].amountDue
, hence the fin fail flag is set, meaning the statement
x++;
is not executed because the while condition is
false
.
As a temporary hack to see what would happen, I tried this:
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
int readFile(ifstream& fin, Customer cust[])
{
int x = 0;
while (x < MAX_CUSTOMERS && fin >> cust[x].customerType
>> cust[x].accountNumber
>> cust[x].numOfBasicServConn
>> cust[x].numOfPremChannels
// >> cust[x].amountDue
)
{
x++;
}
return x;
}
|
With line 46 commented out, I got this output:
The last figure is the uninitialised variable.
This isn't a solution, but a way of looking at what is happening.
If different records have different items present, then limit the part read inside the while loop to that which should always be there, and read the rest as required inside the function body.