Hey guys i'm still having trouble with my bubble sort in else if(choice==2). Where am i going wrong i'm about ready to pull my hair out
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
int i,num[20],n,j,choice,tmp;
cout<< "Please enter 20 integers";
for (i=0; i<20; i++)
{
cout<<"\nEnter next value:";
cin>>num[i];
}
cout<<"\n1.Display original data.\n";
cout<<"2.Sort the data into descending order\n";
cout<<"3.Display the sorted data (Only if you've already sorted)\n";
cout<<"4.Get the address of the first element of array.\n\n";
cin>>choice;
if (choice==1)
{
for (i=0; i<20; i++)
{
cout<<"\n"<<num[i]<<endl;
}
return 0;
}
else if (choice==2)
{
n=20;
for (i = (n - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (num[j+1] < num[j]) /* compare the two neighbors */
{
tmp = num[j]; /* swap a[j] and a[j+1] */
num[j] = num[j+1];
num[j+1] = tmp;
cout<<"Here are your numbers:"<<tmp<<endl;
}
}
}
}
}