How can i write a C++ program which prompts the user to enter names of five countries , stores them in a 2D array,sorts them alphabetical order and prints them on screen.
im unable to make it..plz help
#include <iostream>
using namespace std;
int main()
cout<<"Enter tha names of five countries."<<endl;
int i,j;
char arr[5][20];
for(int k=0;k<=4;k++)
{
cin>>arr[k];
}
for( i=0;i<=4;i++)
{
for( j=0;arr[i][j]!='\0';j++)
{
cout<<arr[i][j];
}
cout<<endl;
}
cout<<"The name of these countries in alphabetical order :"<<endl;
int x[5];
for(i=0;i<=4;i++)
{
x[i]=arr[i][0]-64;
cout<<x[i]<<endl;
}
const int size =5;
int pass=size-1;
int temp;
for(k=0;k<pass;k++)
{
for(j=0;j<pass;j++)
{
if(x[j]>x[j+1])
{ temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
for( i=0;i<=size;i++)
{
for( j=0;j<=15;j++)
{
arr[i][j]=x[i+64];
cout<<arr[i][j];
}
cout<<endl;
}
return 0;
}