0

Hey guys

I know I have posted this type of question before but I want to get to the nitty-gritty of this. I have the following program that sorts ten numbers enter by the user. The program work but I am not able to see the results because the program closes as soon as it done displaying. If i use

`system("pause");`

the programs stops, but I know this is not ideal at all to be used. I have try to use

```
cin.ignore();
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n') ;
```

but this guys don't work all the time. I wanted to know, why is this, why do these two commands some times work and sometimes don't' Thanks for the help

GCard

I have numbered 1 and 2 where i try to use cin.ignore()

```
#include <iostream>
using namespace std;
int main()
{
int numbers[10],temp,i,size = 10;
int original,sorted;
//Creates an array of 10 user supplied numbers.
for(i=0;i<size;i++)
{
cout<<"Please enter a number.\n";
cin>>numbers[i];
} // end of for loop
//outer loop goes through the entire list
for(original=1; original < size; original++)
{
for(sorted = size-1; sorted >= original; sorted--)
{
/*If element sorted-1 is greater than element after
it then swap it.*/
if(numbers[sorted-1] > numbers[sorted])
{
temp = numbers[sorted-1];
numbers[sorted-1] = numbers[sorted];
numbers[sorted] = temp;
}// end of if
}// end of inner for loop
}// end of outer for loop
//print the sorted array.
cout << "The sorted array is \n";
for(i=0;i<size;i++)
{
cout<<numbers[i]<<" "<<endl;
//cin.ignore(); <-------- (1)
}
//cin.ignore(); <-------- (2)
system("pause");
return 0;
}// end of main
```