can someone help me to get my program to sort i have the logic but this is my first time doing a sort program and i cant get it to work can some tell me what i'm doing wrong

#include <iostream>
#include <iomanip>
using namespace std;

void sort();

const int LIMIT = 50; 
int MYARRAY[LIMIT];
    int value,i;
    int x = 0;
    int print = 0;
	int j,temp,min,minx;

int main()
{
    
    bool exit = false;

    
    while(!exit && x < LIMIT)
    {
        cout<<"Enter a number or 999 to quit ";
        cin>>value;
                
        if(value != 999)
        {
            MYARRAY[x] = value;
            x++;
        }
        else
        {
            exit = true;//if value equals 999 exit the loop
        }
       while(print < x)
    {
        cout<<MYARRAY[print]<<endl;//print out the number as long as it is less than i
        print++;
	   }
	}  
sort();  
return 0;    
}

void sort()
{
	
	min=MYARRAY[x];
	minx=i;
	for(j=i+1;j<x;j++)
		if(MYARRAY[j]<min)
		{
			min=MYARRAY[j];
			minx=j;
		}
		if(min<MYARRAY[x])
		{
			MYARRAY[x]=min;
			MYARRAY[minx]=temp;
		}
for(int a=0;a<x;a++)
cout <<setw(4) << MYARRAY[x]<< endl;

}

What is the inital value of i?

If you have it set to nothing, try setting it to a value mabye 0(I think that'll work), then try it.

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.