So I have a code here that is suppose to sort out all the names in order by last name, as well as keep the age with them. I have all that. However, I seem to be having trouble with keeping certain names and ages out of the display based on an age range.
The description says to display all names and ages in order, but discard names if they are below the age of 18, and above the age of 65. I have the first in last name in two dimensional arrays of string, and the age in a basic int array. I found out how to keep the age with the name, but I can't seem to keep the name with the age when I tell it not to display.
I've tried a few if/else statements on my file function and my display function, but I just get wonky results
Here is the code, Pay no mind to the excessive amount of functions I use. I was having trouble with them when I was learning, so now I just like to create many, for learning purposes. I understand the inefficiency
}
int getFile(string filename, string names[][2], int age[])
{
ifstream infile;
string firstname, lastname;
int localcounter = 0;
int ages;
int underages[ARRAYSIZE];
cout << "Please enter the name of the file " << endl;
cin >> filename;
infile.open(filename.c_str());
if (infile)
{
while (infile >> firstname >> lastname >> ages && localcounter < ARRAYSIZE)
Consider creating a class or a struct called Person to store the first name, last name and age of a person. Then you could just have a single array of Persons. Better still would to use a vector<Person>
To filter out the people who are too young or too old, just add code in getDisplay() so it only prints the ones whose age is acceptable.