How to let the user choose between ascending and descending order?

This program prompts the user to input the number of data then the user types the data then the program sorts it alphabetically in ascending order. How to let the user choose between sorting it ascendingly or descendingly? I mean, if he types "A" or "a" then enters it sorts ascendingly and if "D" or "d" then descendingly please help me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  #include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>

char a[50][50],*tmp;
int num,p,c;

void main()
{
	clrscr();
	cout<<"Input number of data: ";
	cin>>num;

	for(int x=0;x<num;x++)
	gets(a[x]);
	cout<<"\n\nUnsorted data: ";
	for(int y=0;y<num;y++)
	cout<<a[y]<<",";
	p=num-1;

	for(p;p>0;p--)
	{
	 for(c=0;c<p;c++)
	  {
	    if(stricmp(a[c],a[c+1])>0)
	     {
	      strcpy(tmp,a[c]);
	      strcpy(a[c],a[c+1]);
	      strcpy(a[c+1],tmp);
	     }
	  }
	}

	cout<<"\n\nSorted data: ";
	 for(int z=0;z<num;z++)
	  cout<<a[z]<<",";




	getch();


}
Last edited on
Topic archived. No new replies allowed.