please tell what am I doing wrong.

include <iostream>

using namespace std;

int main()
{
char name[3][30];
int i, j;

for(i=0;i<=2;i++)
{
    cout << "Please enter name: ";
    cin >> name[i];
}

for(i=0;i<=1;i++)
{
    for(j=i+1;j<=2;j++)
    {
        char temp;

        if(name[i] > name[j])
        {
            temp = name[i];
            name[i] = name[j];
            name[j] = temp;
        }
    }
}

for(i=0;i<=2;i++)
{
    cout << endl <<  name[i] << endl;
}

cin.ignore();
cin.get();

//system("pause");

}

void BubbleSort()
{
  int i, j, flag = 1;    // set flag to 1 to start first pass
  int temp;             // holding variable
  int numLength = num.length( ); 
  for(i = 1; (i <= numLength) && flag; i++)
 {
      flag = 0;
      for (j=0; j < (numLength -1); j++)
     {
           if (num[j+1] < num[j])      // descending order simply changes to >
          { 
                temp = num[j];             // swap elements
                num[j] = num[j+1];
                num[j+1] = temp;
                flag = 1;               // indicates that a swap occurred.
           }
      }
 }
 return;   //arrays are passed to functions by address; nothing is returned
}

I hope this will help you :)
wanna know concept?
Click Here

dariaveltman

please tell what am I doing wrong.

First, please let us know what you are confused about. If you don't know exactly where you are confused in the code or how the code is supposed to work try telling us what you already do know and how you got there. This will help us understand exactly where you were left off as we can continue the discussion from that point instead of possibly repeating something that you may already know.

roc.ky89

I hope this will help you :)
wanna know concept?

I think your post is slightly inappropriate as we should be leading the OP towards his own conclusion instead of telling him the exact answer. By just telling him, they learn nothing. This does not help them later in the future when this type of exercise would have built a better programming structure for the programmer.

Second, you copied and pasted someone elses code. Granted, you did link a site to the page but not until you scroll down do we realize it was copied and pasted from this page. We don't, or at least I don't, expect you to paste it in MLA format, but a simple (CODE WAS COPIED FROM THIS SITE) would have been sufficient.

Hi saith,
Actually I did that for two things. I wanted to make him realize that there is lot of source to study out there. You just can search with keywords on google. Because thats how I studied 80% of things from this kind of sources. So he can save his time for next time.
And second, I copied code because it was containing comments. If there was no comments then I would have not copied that code. And pasted that link so if he wants he can learn the concept and understand it by himself.
Ya everybody have there own way of thinking, thats how I think,
Best regards,
Rocky

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.