C++ question #2 alphabetical via string

Here is my code so far but I cant get it to alphabetize correctly. Please explain what I am doing wrong b/c its driving me crazy!!

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

int main()
{
string word1,
word2,
word3,
d,
e,
f; // strings input by the user



cout << "This program will input three strings and"
<< "\ndisplay them in alphabetical order.\n\n"
<< "Enter three strings, separated by blanks ";

cin >> word1 >> word2 >> word3 ;
cout << "You entered:\n\n" << word1 <<endl
<< word2 << endl << word3 <<endl <<endl;


cin >>word1;
cin >>word2;
cin >>word3;
if ( word1>word2 && word1>word3)
d = word1;
else
if ( word1>word2 || word1>word3 )
e = word1;
else
f = word1;
if (word2>word1 && word2>word3 )
d = word2;
else
if ( word2>word1 || word2>word3 )
e = word2;
else
f = word2;
if ((word3>word2)&&(word3>word1))
d = word3;
else
if ((word1>word2)||(word1>word3))
e = word3;
else
f = word3;
cout
<<"\nsorted alphabatical\n"
<<d
<<"\n"
<<e
<<"\n"
<<f
<<"\n";

cout << "\n\nIn alphabetical order:\n\n";






system("pause");

return(0);

}
Well, for simple sorting that isn't that time critical, I would just store the strings in an array/vector and use a bubble sort:

http://en.wikipedia.org/wiki/Bubble_sort
Topic archived. No new replies allowed.