LineUp C++ what I have so far

Can any one help me its not reading my File

A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be in front of the line and Yolanda will be at the end.

Write a program that will read in a file of names. Names should be read until there are no more names to be read. Use LineUp.txt as a test file for your program.

Once all the names have been read in display which student will be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.


#include<iostream>
#include<string>
#include<fstream>
using namespace std;

int main()
{
//variables
string firstInLine; //holds the current value of the first person in line
string lastInLine; //holds the current value of the last person in line
string name; //name read in from the user

ifstream inNames; //input file

//open the file for reading
inNames.open("lineup.txt");

if (!inNames) //file did not open properly
{
cout << "The lineup.txt file did not open properly" << endl;
return 1000; //exit the program

//The file did open properly

//set initial values to first name in the file
inNames >> name; //Read in the first name in the file

firstInLine = name;
lastInLine = name;

while (inNames >> name) //Read the next name in the file
{
if (name < firstInLine)
firstInLine = name;
{
if (name < lastInLine)
lastInLine = name;
}

cout << endl << firstInLine << "This is the name of the student in front of the line: ";
cout << lastInLine << " This is the name of the student at the end of the line." << endl;

inNames.close();

return 0;
}
Topic archived. No new replies allowed.