I need to write a program to enter 3 names then display the name is aphabetical order. Example Jessie, sam, and chris. the program should display:
chris
Jessie
sam

Please help

If I could write it, I wouldn't be asking for help. i can sort 2 strings but can't sort 3 strings.
// Get the first name.
cout << "Enter a name (last name first): ";
cin.getline(name1, SIZE);

// Get the second name.
cout << "Enter another name: ";
cin.getline(name2, SIZE);

// Display them sorted in alphabetical order.
cout << " Here are the names sorted alphabetically:\n";
if (strcmp(name1, name2) < 0)
cout << name1 << endl << name2 << endl;
else if (strcmp(name1, name2) > 0)
cout << name2 << endl << name1 << endl;
else
cout << "You entered the same name twice!\n";
return 0;

>>If I could write it, I wouldn't be asking for help.
This doesn't work this way. Ancient Dragon wanted you to tell that you need to give more detail and the account of the effort you put in.
Also, everyone is supposed to read the Sticky thread:http://www.daniweb.com/forums/thread78223.html and also the Announcement: http://www.daniweb.com/forums/announcement8-2.html

Moreover, you are suppose to put your code in the code tags.

Now as far as your problem is concerned:
You need to get some lesson on sorting. Read the following article I found by using Google:http://www.daniweb.com/forums/thread6713.html

>i can sort 2 strings but can't sort 3 strings.
If you can sort two strings, you know how to sort three. This is especially easy because there's a smallest, a largest, and only one inbetween. So all you need to do is find the smallest and largest before you can determine the order.

Here is the program buddy . Through this u can sort upto 3 names . any reference if u want just mail me - aswinantonywilson@gmail.com. k.

#include<iostream.h>
#include<conio.h>
#include<string.h>


void main()
{
clrscr();
char str1[20],str2[20],str3[20];
cin>>str1>>str2>>str3;
cout<<"The order is \n";
if((strcmp(str1,str2)<0)&&(strcmp(str2,str3)<0))
{
cout<<str1<<","<<str2<<","<<str3<<".";
}
if((strcmp(str2,str3)<0)&&(strcmp(str3,str1)<0))
{
cout<<str2<<","<<str3<<","<<str1<<".";
}
if((strcmp(str3,str1)<0)&&(strcmp(str1,str2)<0))
{
cout<<str3<<","<<str1<<","<<str2<<".";
}
getch();
}
Comments
No need to revive a 3-year old thread and post a code, without indentations. Also I doubt that the OP is searching for that program.

Bump a 3 year old thread and put code on it that wont work unless the compiler was made befor 1998? The code you posted wont even work for all casses. What if the order is string 3, string 2 and string 1? No where do you print that combination.

Edited 4 Years Ago by NathanOliver

This article has been dead for over six months. Start a new discussion instead.