Switch to full style
For C/C++ coders discussions and solutions
Post a reply

c++ general programming

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?



Post a reply
  Related Posts  to : c++ general programming
 draw General Path     -  
 General Error: Style data     -  
 General call (Invoke) to method     -  
 ALP programming     -  
 C++ programming     -  
 javascript programming     -  
 hello pls i want the codens in c# programming     -  
 why to use scanf in c programming     -  
 Safe Programming     -  
 How do you know when to use the right programming language?     -