Can someone tell me why this isn't working? Should be reading last name alphabetically?

Okay, so my teacher wants us to have the first name and last name in alphabetical order print out. I am getting the first one, Angie, to print out...but I cannot get the last one, Zach, to print. All I am getting is aaaaa. Can someone help?

Here is the list in my SetOne.txt
John
Mary
Tom
Susan
Bill
Angie
Zach
Larry
Paul
Carl


Here is my program:


#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
ifstream inputFile;

int numStudents;
string name, lastStudent, firstStudent;

cout << "Input number of students." << endl;
cin >> numStudents;

while ((numStudents < 1) || (numStudents > 25))
{ cout << "Please enter a number between 1 and 25.";
cin >> numStudents;
}

firstStudent = "zzzzzzz";
lastStudent = "aaaaaaa";



if (numStudents = 10)
{ inputFile.open("SetOne.txt");
inputFile >> name;
while (!inputFile.eof())
{
if (name < firstStudent)
firstStudent = name;
inputFile >> name;
}
while (!inputFile.eof())
{
if (name > lastStudent)
lastStudent = name;
}
inputFile.close();
cout << firstStudent << " " << lastStudent;
}





system("pause");
return 0;
}
1
2
3
4
5
while (!inputFile.eof())
{
if (name > lastStudent)
lastStudent = name;
}

This loop never gets executed because the inputFile is at eof after the previous loop. You should do the check for the lastStudent in the previous loop as well and scrap this one.
Even after doing that, it gives me "aaaaaaa" as an output... /:
Can we see the new code? (In [code][/code] tags, please)
Topic archived. No new replies allowed.