Sorting Names Alphabetically

Hello, I am having a little trouble writing this program that lets the user enter an amount of names equal to the number of students in the class. I got up to the part where I enter the names, but sorting the names is proving to be quite difficult at my level at the moment. Can anyone please tell what I should add?

Here is my program:

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
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	const int SIZE = 30;
	int num_student,		//number of students
		count = 0;
	char students[SIZE];    //name of student(s)

	cout << " How many students are there in this class? ";
	cin >> num_student;
	cout << "\n What are the students names? First names only." << endl;

	for(count = 1; count <= num_student; count++)
	{
		cin.getline(students, SIZE);

		if(strcmp(students) < 0)
		{
			cout << students << endl;
		}
	}

	
	/*do
	{
		count++;

		cin.getline(students, SIZE);

	}while(count <= num_student);
	*/


	return 0;
}


Edit: I don't know if I should use a do loop or a for loop...
Last edited on
Topic archived. No new replies allowed.