This is the program that needs to write a code to read data from file. The file looks like:
1234 200.55
5678 1234.56
9876 2.33
I need to store the first number as the account number and the second one as the balance of the account.
#include<iostream>
#include<fstream>
using namespace std;
const int MAX_NUM=100;
int read_accts(int acctnum[], double balance[], int max_accts);
int main()
{
int acctnum[MAX_NUM];
double balance[MAX_NUM];
int max_accts=0;
int num_accts;
num_accts = read_accts(acctnum,balance,max_accts);
return 0;
}
int read_accts(int acctnum[],double balance[],int max_accts)
{
ifstream infile;
infile.open("information");
while (infile >> acctnum[max_accts] && max_accts < MAX_NUM)
{
infile >> balance[max_accts];
max_accts++;
}
for (int i=0; i<=max_accts; i++)
{
cout << acctnum[i]<<endl;
cout << balance[i]<<endl;
}
infile.close();
return max_accts;
}
The output of this program is
0
0
It should be same as the text file has. it shouldn't be 0 and 0.
Thanks in advance Any help is appreciated.