Adding limits to user input

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.

Thank you.

Just line 19-22 everything else works fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <fstream>
using namespace 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;
}
Last edited on
Topic archived. No new replies allowed.