Hello everyone I am trying to do this assignment in the book: Write a program that reads four words (as character strings) and display them in increasing and decreasing alphabetical sequence.
I have done the 1st (easy) part but not sure how to go about displaying words in alphabetical order.
Here is what I’ve got so far:

int main()
{
string word1;
string word2;
string word3;
string word4;
string stringEval;


cout << "Enter four words using spaces between them: " << endl;
cin >> word1 >> word2 >> word3 >> word4;

Thank you for your help!

Edited 3 Years Ago by happygeek: fixed formatting

I asked for help not for giving me a hard time
but here is what i've got so far

// File:
// (description)
//
// Input:
// Output
//--------------------------------
// Class: CS210 Instructor: Ravi Gandham
// Assignment:  Date Assigned:
// Programmer:  Date Submitted:


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


int main()
{
string word1;
string word2;
string word3;
string word4;
string stringEval;


cout << "Enter four words using spaces between them: " << endl;
cin >> word1 >> word2 >> word3 >> word4;


if (word1 > word2){
cout << "....." << word1;}
else
cout << "....." << word2;


if (word3 > word4){
cout << "....." << word3;}
else cout << "...." << word4;


/*stringEval.find
if ((word1 == 'A') && (word1 == 'a'))
*/


system("pause");
return 0;
}

Edited 3 Years Ago by happygeek: fixed formatting

Comments
a) you should have posting this first then, and b) it's about time you learnt about code tags

You can use compare since you are using strings rather than C-strings. Or strcmp could work, as the last poster mentioned, though you'd have to convert from strings to C-Strings.

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
bool compare(string s1,string s2)
{
	if(strcmp(s1.c_str(),s2.c_str())>0)
		return true;
	else
		return false;
}
int main()
{
string a[]={"abc","dafa","eeee","what"};
	vector<string> names(a,a+4);

// increasing alphabetical  sequence
sort(names.begin(),names.end());
	
	for(vector<string>::const_iterator itr=names.begin();itr<names.end();itr++)
	{
		cout<<*itr<<" \t";
	}
	cout<<endl;

// decreasing alphabetical sequence
	sort(names.begin(),names.end(),compare);
	for(vector<string>::const_iterator itr=names.begin();itr<names.end();itr++)
	{
		cout<<*itr<<"\t";
	}

}
This question has already been answered. Start a new discussion instead.