ok i got the function to work. still not sure why if i only put in 10 numbers and hit enter it wont run the program. I have to enter 10 more number before it will sort them.
Code:
#include<iostream>using namespace std;
int bubbleSort(int);
int main()
{
int temp=0;
int num[20];
cout<<"Pleas enter a series of numbers(no more than 20): "<<endl;
for(int i=0; i<20; i++)
{
cin>>num[i];
}
while(!cin){//says while the input is not equal to an interger go to next line
cout<<"Error, Please enter a series of numbers: "<<endl;
for(int i=0; i<20; i++)
{
cin.clear();//clears the input from num[i]
cin.ignore(256,'\n');//flushes the input stream
cin>>num[i];
}
}
cout<<endl;
cout<<"Orignally entered array is: "<<endl;
for(int j=0; j<20; j++)
{
cout<<num[j];
cout<<endl;
}
cout<<endl;
bubbleSort(temp);
cout<<"Sorted Array is: "<<endl;
for(int i=0; i<20; i++)
{
cout<<num[i]<<endl;
}
system("pause");
}
int bubbleSort(int temp)
{
int num[20];
for(int i=0; i<19; i++)
{
for(int j=0; j<19; j++)
{
if(num[j]>num[j+1])
{
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
return temp;
}