Hello everyone! I am new with C++ and I am trying to write 10 numbers via the "cin" command and then to sort them ascending (e.g if I wrote 32, 23, 65, 45, 22, 12, 3, 5, 8, 1, 10; the Command Prompt should sort it so it'll look like this: 1, 3, 5, 8, 10, 12, 22, 23, 32, 45, 65). 'Til yet I managed only to write the numbers because the Command Prompt closes after I write them all.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include<iostream.h>
#include<conio.h>
using namespace std;
main()
{
int number[10],i,a,b,c,d,t;
cout<<"Enter the elements of the array:"<<endl;
for(int i=0;i<10;i++)
{
cout<<"Enter number for cell "<<i<<endl;
cin>>number[i];
}
cout<<endl<<"Thank You! The data entry is over."<<endl;
cout<<"\a\a";
for(int j=0; j<10; j++)
{
for(int k=0; k<9; k++)
{
if (number[k]>number[k+1])
{
a=number[k];
number[k]=number[k+1];
number[k+1]=a;
}
}
}
cout<<"The list in ascending order is ";
cout<<endl;
for(i=0;i<10;i++)
cout<<number[i]<<"\t"<<endl;
}
|
Any possible help? Command prompt just closes after I write the 10 numbers.