Okay, so I am EXTREMELY new to programming and my teacher is not exactly a great one, sadly.
I am attempting to sort a string alphabetically.
For example:
Prompt to enter name:
Alex
Joe
John
Bill
Cait
Then sort and print:
Alex
Bill
Cait
Joe
John
Here's what I have so far:
int _tmain(int argc, _TCHAR* argv[])
{
int num_child; // Number of children in the class
string name[100];
cout << "Please tell us how many children are in your class:" << endl;
cin >> num_child;
for(int i = 0; i < num_child; i++)
{
cout << "Child #: " << i+1 << "'s name is?" << endl;
cin >> name[i];
}
for(int j = 0; j < num_child; j++)
{
strcmp(name[j].c_str(), name[j+1].c_str());
if(name[j] > name[j+1])
{
name[j] = name[j+1]
}
}
cout << "The students in your class are" << endl;
for(int k = 0; k < num_child; k++)
{
cout << name[k] << endl;
}
I've entered:
Alex
Jill
Jake
and the current outcome is:
"The students in your class are:"
Alex
Jake
... can anyone point me in the right direction?
EDIT: Yes, this is for a class, so please don't just give me the code for it. I want to understand how to actually do it.