i want to make the menu in this program a function so it will be at the bottom and you simply call it without it being in the main. I tried but when i did it didnt like the way i returned it to the switch...
Code:#include<stdio.h> #include<stdlib.h> int genrand() { int random; random = 1+rand() % 999 ; while(random==0)random= 1+rand() % 999 ; return random; } void main() { srand (time(NULL)); int a,ary[50],random; for(random=0;random<50;random++) { ary[random]='\0'; } while(1) { printf("\n***************************************"); printf("\n MENU "); printf("\n1. Fill array with random numbers "); printf("\n2. Print the array "); printf("\n3. Search the array "); printf("\n4. Sort the array "); printf("\n5. Quit "); printf("\n***************************************\n"); scanf("%d",&a); switch(a) { case 1: { for(random=0;random<50;random++) { ary[random]=genrand(); } break; } case 2: { for(random=0;random<50;random++) { printf("%d ",ary[random]); } break; } case 3: { int n,c=0; printf("\nEnter search number: "); scanf("%d",&n); for(random=0;random<50;random++) { if(ary[random]==n){ printf("\nNumber is at position(s): %d",(random+1)); c=1; } } if(c==0)printf("\nNumber doesn't exist."); break; } case 4: { int i; int x; int y; for(i=0;i<50;i++) { for(x=0;x<49;x++) { if(ary[x]>=ary[x+1]) { y=ary[x]; ary[x]=ary[x+1]; ary[x+1]=y; } } } break; } case 5: { exit(0); } default: { printf("\nINVALID CHOICE: "); } } } }