Hi, I'm a newbie to this site, but I will soon be an active member. Currently I'm writing a program where one of my methods has to read data from a text file and set it to an array.
I then need to display that data in the console, but I only want to display what there is to display. Right now, it lists 45 items (the maximum amount it should display), but it will list blank lines after it has finished listing whatever data there was, and I need it to stop once there is no more data.
One person told me to make it loop until the new variable = the old variable,
but I really don't understand how to do this.
Here's what I got:
void ViewData()
{
int x=0;
int y=0;
int sum = 0;
int n = 0;
double TotalOwed=0.00;
char cMemberNumber [1000];
string MemberNumber [1000];
char cMemberName [1000];
string MemberName [1000];
char cSchool [1000];
string School [1000];
char cYearJoined [1000];
string YearJoined [1000];
char cAccountBalance [1000]; //char
string AccountBalance [1000]; //double?? string
//int TotalAmount [1000];
ifstream OpenFile("data.txt", ios::in);
// Reads the data into the program
while (!OpenFile.eof())
{
x++;
OpenFile.getline(cMemberNumber,2000);
MemberNumber [x] = cMemberNumber;
OpenFile.getline(cMemberName,2000);
MemberName [x] = cMemberName;
OpenFile.getline(cSchool,2000);
School [x] = cSchool;
OpenFile.getline(cYearJoined,2000);
YearJoined [x] = cYearJoined;
OpenFile.getline(cAccountBalance,2000);
AccountBalance [x] = cAccountBalance;
//TotalAmount [1000] = atof(AccountBalance [1000]);
}
OpenFile.close();
cout << "Current Account Balances: " << endl;
cout << endl;
cout << setw(18) << "MemberNumber" << setw(15) << "MemberName" << setw(13) << "School" << setw(18) << "Year Joined" <<
setw(15) << "Amount Owed" << endl;
do
{
x++;
y++;
cout << endl;
cout << "Line " << x << ":" << setw(5) << MemberNumber [y] << setw(18) << MemberName [y] << setw(18) << School [y] << setw(12) << YearJoined [y] <<
setw(15) << AccountBalance [y] << endl;
}while(x<=44);
//cout << endl;
//cout << "Total Amount Owed: " << TotalOwed << endl;
system("pause");
}