I have been searching a lot on this forum, and it seems there is multiple topics around this, however, I try and do the exact same as some of the guides that are on here but it would never work for me. Can someone please look at this code and tell me what I am missing.
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
ofstream outputFile;
ifstream inputFile;
int initial, number, count;
string name, front, end;
outputFile.open("StudentList.txt");
cout<<"Enter how many students are in the class: ";
cin>>number;
fflush(stdin);
for (initial =1; initial <=number; initial++)
{
cout<<"Enter full name of student "<<initial<<" : ";
if (number< 3 || number > 30)
{
cout << "Invalid choice. Try again." << endl;
}
getline (cin, name);
outputFile << name << endl;
fflush(stdin);
{
if (initial == 1)
{
front=name;
end=name;
}
if (name<front)
front=name;
if (name>end)
end=name;
}
}
cout << "The first person " << front << endl;
cout << "The last person " << end << endl;
outputFile.close();
inputFile.open("StudentList.txt");
while (getline(inputFile, name))
{
cout<<name<<endl;
}
inputFile.close();
fflush(stdin);
cin.get();
return 0;
}