Understand the algorithm first.
What you're doing is somewhat jumbled up(trying to sort while taking the input and so on..)
If this is supposed to be bubble sort, read the wikipedi article on it.
If you aren't required to write the sort function yourself ; do something like this :
Code:
#include<algorithm>
#include<array>
#include<iostream>
using namespace std;
bool comp(int x,int y){return x<y;}
int main()
{
array<int, 5> foo = {4,67,22,5,7};
sort(foo.begin(),foo.end(),comp);
for(auto x:foo)cout<<x<<endl;
return 0;
}