Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
How Can I Pass a Menu Function Int Value Back To Main To Access Other Menu Functions Using Switch Statement?

I'm doing this for part of a school project and I am so lost and this is only the beginning of it. Our professor wants us to have 4 menu functions. Each menu has options to access other functions within the program. First, we are asked to have the program state if we would like to start or quit. That's no problem. My problem is when I run the main menu function and select an option I cannot get my choice to return to main to run the switch case to access the other menus. Right now I have all the other menus saying "coming soon..." just so I know I am getting it right. I'll add more once I get past this part. This is my first post here so I apologize if this is a lot of code to post. I greatly appreciate any help. Thank you.

#include <stdio.h>
#include <stdlib.h>


int main()
{
    //declare all working variables: mOption, FManOption, COption...etc...
    int MOption = 0;
    int FManOption = 0;
    int FOption = 0;
    int COption = 0;
    int userChoice = 0;


    int n = mainMenu();

        switch(n)
        {
            case 1: while(FManOption != 3)
                    {
                        FManOption = FishermanMenu();
                        switch(FManOption)
                        {
                            case 1: //get a fisherman
                                    //count fisherman
                                    break;
                            case 2: //prompt for a ssn, validate, search
                                    //if found display everything about this fisherman
                                    break;
                            case 3: //hit any key to go back to main menu
                                    //reset FManOption
                                    break;
                            default: "error!";
                        }//end switch(FManOption)
                    }//end while(FManOption != 3)
                    break;
            default: printf("error");
        }

    return 0;
}
int mainMenu()
{
  int option = 0;

    printf("-------Welcome to the Fishing Tournament Main Menu!-------\n\n");
    do
    {
        printf("1 - Fisherman menu\n");
        printf("2 - Fish menu\n");
        printf("3 - Tournament(Catch) menu\n");
        printf("4 - Close Tournament (determine winner)\n");
        printf("5 - Quit Program\n\n");
        printf("Please select a menu option: ");
        if (scanf("%d", &option) != 1) /* check scanf() return value for input errors */
        {
          /* handle input error */
          return -1;
        }
    } while (option < 1 || option > 5); /* check the range of option ( 1 - 5) */

    return option; /* finally return the final correct option */
}

int FishermanMenu()
{
    printf("Coming soon...");
    /*
    -1-Register fisherman

    -2-Search fisherman

    -3-Go back to main menu
    */
    //FManOption
}//end Fisherman Menu
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your mainMenu() function doesn't return anything other than 0, in addition you ignore the return value in main, when you call mainMenu(); (this shouldn't even compile btw), this is probably what you are looking for,

int mainMenu(void)
{
  int option = 0;

    printf("-------Welcome to the Fishing Tournament Main Menu!-------\n\n");
    do 
    {
        printf("1 - Fisherman menu\n");
        printf("2 - Fish menu\n");
        printf("3 - Tournament(Catch) menu\n");
        printf("4 - Close Tournament (determine winner)\n");
        printf("5 - Quit Program\n\n");
        printf("Please select a menu option: ");
        if (scanf("%d", &option) != 1) /* check scanf() return value for input errors */
        {
          /* handle input error */
          return -1;
        }
    } while (option < 1 || option > 5); /* check the range of option ( 1 - 5) */

    return option; /* finally return the final correct option */
}

int main(void)
{

  int n = mainMenu(); /* save the result to n */

  /* your code */

  return 0;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda