/* assignment3: */
int main(void) //users choice
{
int choice = 0; /*users choice*/
/*offer user choice of options*/
printf("Please enter a number from 1 through 6. Your choice will execute the following with a predetermined array;\nChoose an option;\n");
printf("1. Sequential Search\n");
printf("2. Binary Search\n");
printf("3. Bubble Sort\n");
printf("4. Selection Sort\n");
printf("5. Insertion Sort\n");
printf("6. End Program\n");
while (userChoice != 6) { /*while user does not want the program to end*/
int numberArray[SIZE] = {17, 2, 35, 29, 99, 12, 67, 54, 45, 1}; /*set up array to default every time array is accessed by user*/
printf("\n\n\nEnter a value from 1 through 6:"); /*prompt user*/
scanf("%d", &choice);
switch(choice) { /*search for users choice*/
case 1: /*execute sequential search*/
sequentialSearch(numberArray, SIZE);
break;
case 2: /*execute binary search*/
insertionSort(numberArray, SIZE);
binarySearch(numberArray, SIZE);
resetArray(numberArray);
break;
case 3: /*execute bubble sort that is not organizational purposes only*/
printf("Unsorted array:\n");
displayArray(numberArray, SIZE);
bubbleSort(numberArray, SIZE);
printf("Sorted array:\n");
displayArray(numberArray, SIZE);
resetArray(numberArray);
break;
case 4: /*execute selection sort*/
printf("Unsorted array:\n");
displayArray(numberArray, SIZE);
selectionSort(numberArray, SIZE);
printf("Sorted array:\n");
displayArray(numberArray, SIZE);
resetArray(numberArray);
break;
case 5: /*execute insertion sort*/
printf("Unsorted array:\n");
displayArray(numberArray, SIZE);
insertionSort(numberArray, SIZE);
printf("Sorted array:\n");
displayArray(numberArray, SIZE);
resetArray(numberArray);
break;
case 6: /* lets userknow that the program is ending*/
printf("Program has ended.\n");
break;
default: /* lets user know they put in incorrect input*/
printf("Incorrect input. Please enter a number 1 through 6 only.\n");
break;
} /*end switch*/
} /*end while*/
return 0; /*indicates successful termination*/
} /*end main program*/
Admin Edit: Please use code tags when posting your code. Code tags are used like so =>
Thanks,
PsychoCoder

New Topic/Question
Reply
MultiQuote









|