Why the selection sort output not appear? Anybody knows how to correct it?

#include < iostream >
#include < string >
#include < cmath >
#include < iomanip >
#include < fstream >
using namespace std;

	void SelectionSort ( int *y , int n )//selection sort function 
	{
		int i , min , minat ;
		{
			for ( i = 0 ; i < 3 ; i++ )
			{
			minat = i ;
			min = y [ i ];

				if ( min < y [i ] )   
				{
				minat = i;  
				min = y [ i ];
				}
			}
	  int temp = y [ i ] ;
	  y [ i ] = y [ minat ];  //swap 
	  y [ minat ] = temp; 
	  
		}

}
void printElements ( int *y , int x, int n ) //print array elements
{
	int i = 0 ;
	for ( i = 0 ; i < 3 ; i++ )
    cout << " " << x << " " << y << endl;
}
	
void main()

{
	int x, y;
	ifstream inFile("jes.txt");

	for (int i = 0; i < 3; i++) 
	{
		 if (inFile >> x >> y) 
		 {  // Reading is successful
			if (inFile.fail())
			{
			cout << "Error! Cannot open file! \n";
			}
			cout <<" "<< x <<"  "<<y<< endl;
		}
	 } 	
}

>>Why the selection sort output not appear?
Because it is never called.

how to called the selection sort?what must i add?

look at line 8. It wants an int array and the number of items in the array. In main() you have declared neither.

in main() you need to declare an int array then fill it with some numbers. After that you can call the selection sort function to re-arrange the numbers in either ascending or descending sequence.

Dear Ancient Dragon,

so, I must declare like this?

void main ()
{
	int y[]={20,30,25};
	int x ;

That's one way to do it, yes.

but, i want to call the data from the text file...because, i have 100-300 data, So it it another way, to do?

delare the array then fill it from the data that is read from the text file. I'm certain that you know how to do that by now.

int array[255] = {0};
// now read the values from the text file

delare the array then fill it from the data that is read from the text file.

fill it from the data that is read mean if I have 3 data so must write..and if i have 100 data, so i must write also..is it like that?

Here's an example.

const int max = 255;
int array[max] = {0};
ifstream in("filename.txt");
int i = 0;
while( i < max && in >> array[i] )
   i++;

i have change like this, but the output only display for i=0 only.

and it said in is using without initialized.
in is for what actually? cin?

output
1 20
1 20
Press any key to continue

void main ()
{
    const int max = 4;
	int x,y, in;
    int array[4] = {0};
	ifstream inFile("jes.txt");
    int i=0;
	while( i < 4 && in >> array[i] )
	 i++;
	
	{
		 if (inFile >> x >> y) 
		 {  // Reading is successful
			if (inFile.fail())
			{
			cout << "Error! Cannot open file! \n";
			}
			cout <<" "<< x <<"  "<<y<< endl;
		 }
	}	 

    cout << " "<<x<<" "<<y<< endl;
}
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.