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;

}``````
2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by Gnome_101

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.