another sort useless program
anyone that wants to call me poopy thats ok !
the problems im having with this useless program is when the user hits 2 for unsorted its unsorted but after its sorted it remains that way. how can this be fixed? also it suppose to quit with the q but doesnt!
Code:
#include <stdio.h>
#include <stdlib.h>
void sort(int *array);
int main(int argc, char *argv[])
{
char answer[2] ;
int num, c;
int array[12]={ 34, 12, 22, 109, 7, 6, 709, 100, 1, 4,
23,24};
printf("%25c----------------\n",0);
printf("%25c sort or unsort?\n",0);
printf("%25c----------------\n");
printf("\n");
printf("would you like the numbers sorted or unsorted?\n");
printf("type 1 for sorted. 2 for unsorted. q to quit\n");
do{
gets(answer);
num = atoi(answer);
switch(num){
case 1:
printf("%22c---------Sorted----------\n");
sort(array);
for(c = 0; c < 12; c++)
printf("%i\t",array[c]);
printf("\n");
break;
case 2:
printf("%22c------Unsorted-------\n");
for(c = 0; c < 12; c++)
printf("%i\t",array[c]);
break;
printf("\n");}
}
while(num != 'q');
system("pause");
return 0;
}
void sort(int *array)
{
int a, b, temp;
for(a = 0; a < 12; a++)
for(b = 0; b < 12; b++)
if(array[a] < array[b])
{
temp = array[a];
array[a] = array[b];
array[b] = temp;
}
}