Hey I'm trying to get this code going but i can't get my if(choice==2) to output anything any ideas?
#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;
}
if (choice==2)
{
for (i=0; i<n-1; i++)
{
for (j=0; j<n-1-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;
}
}
}
}
}