I have x and y array...After I have sort y, it succefully sort the y. but for x, there is some number that are not sort like this

x y30 1
45 1
46 1
15 1

I want the x sorting also...like this

x y30 1

15 1
30 1
45 1
46 1


anybody knows how to sort x also...
the input file is in the attachement file.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int y[200],x[200];
int myfile;
int main()
{
	int i,a,b,count;

    void selectionSort();
	ifstream infile;
	infile.open("916-3-2-1.txt");
	if (!infile)
	{
        cout << "Tak Boleh Buka Fail";
        exit(1); // terminate with error
    }
		ofstream myfile;
		myfile.open("916-3-7.txt");
		if (myfile.is_open())
		{
		myfile<<"Before Sort"<<endl;
			myfile<<"-----------"<<endl;

			for(i=0; i<100; i++)
			{
			y[i];	
			}

			count=0;
			while(infile>>b>>a)
			{
				y[count]=a;
				x[count]=b;
				//myfile<<setw(5)<<x[count]<<"   "<<y[count]<<endl;
				count=count+1;
			}
				myfile<<endl;
    
				infile.close();
				int j,min,minat;
    
			

				for(i=0;i<count;i++)
				{
				minat=i;
				min=y[i];

					for(j=i+1;j<count;j++) //select the min of the rest of array
					{
					if(min<y[j] )   //ascending order for descending reverse
		 
						 {
						 minat=j;  //the position of the min element 
						 min=y[j];
			  			}
					 }

				int temp=y[i], temp1=x[i] ;
				y[i]=y[minat];  //swap 
				y[minat]=temp;
				x[i]=x[minat];
				x[minat]=temp1;

				}
    //myfile<<"After Sort in Descending Order"<<endl;
	//myfile<<"------------------------------"<<endl;
	for(i=0;i<count;i++)
    myfile<<setw(5)<<x[i]<<"   "<<y[i]<<endl;
	myfile<<"\n";
	
	{
	for(i=0;i<count;i++)
	{
		minat=i;
		min=y[i];
      for(j=i+1;j<count;j++) 
	  {
		  if(  min<y[j] && min>x[j])  
			  
		  {
			  minat=j;  
			  	min=y[j];

		  }
	  }
	  int temp1=x[i],  temp=y[i];
	 x[i]=x[minat];
	  x[minat]=temp1; 
	  y[i]=y[minat];  //swap 
	  y[minat]=temp;
	}
    myfile<<"After Sort "<<endl;
	myfile<<"----------"<<endl;
	for(i=0;i<count;i++)
    myfile<<setw(5)<<x[i]<<"   "<<y[i]<<endl;
	return 0;
	}
}return 0;
	}

When are you going to start formatting your code so that the code within brackets lines up? I don't know how many times you have been asked to do that so that your code is readable. Either use spaces or use tabs, but not both. Maybe that will help. You either don't know what we are talking about regarding indentation or you simply refuse to do it. There is also the "Preview Post" button. Hit it before posting and it'll show how things will look. Fix it so it lines up right, then post.

commented: Well said, Bravo!! +16
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.