Sat Apr 11, 2009 7:16 pm
Hi everyone.
I am newbie to this forum and I have some troubles with sorting names in c++.
My code is:
int main()
{
string name1, name2,name3;
string store;
cout<<"Enter name1\n";
cin>>name1;
cout<<"Enter name2\n";
cin>>name2;
cout<<"Enter name3\n";
cin>>name3;
if(name1>name2)
{
store=name1;
name1=name2;
name2=store;
}
if(name2>name3)
{
store=name2;
name2=name3;
name3=store;
}
if(name1>name3)
{
store=name1;
name1=name3;
name3=store;
}
cout<<"Alphabetically,those names are:"<<endl;
cout<<name1<<endl<<name2<<endl<<name3<<endl;
system("pause");
return 0;
======================
when I run the program,and if I enter for example John,Bernard and Albert;
I get Bernard,Albert,John.
PS:I want to use only if statement like I tried it .No arrays.
Could any one help me please?
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.