Console menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JeremyT
    New Member
    • Apr 2007
    • 4

    Console menu

    hi there, could any of you pros help me out on how to start an menu-based console application using C++ functions? I dont think i'd be able to cope with OOD as im still new to c++. Not too sure on how to call out each function from the menu
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by JeremyT
    hi there, could any of you pros help me out on how to start an menu-based console application using C++ functions? I dont think i'd be able to cope with OOD as im still new to c++. Not too sure on how to call out each function from the menu
    Are you looking for something that involves Design Patterns? Is this supposed to be a GUI, or a text-based menu?

    We need a bit more to help - how are you trying to call the function from the menu now?

    Comment

    • JeremyT
      New Member
      • Apr 2007
      • 4

      #3
      Originally posted by sicarie
      Are you looking for something that involves Design Patterns? Is this supposed to be a GUI, or a text-based menu?

      We need a bit more to help - how are you trying to call the function from the menu now?
      Thanks for the reply, it's supposed to be a text-based menu. It's supposed to be able to launch functions to find ID's, write new ID's and save new ID's as well.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by JeremyT
        Thanks for the reply, it's supposed to be a text-based menu. It's supposed to be able to launch functions to find ID's, write new ID's and save new ID's as well.
        Seems pretty straightforward , what part are you getting stuck on?

        Comment

        • JeremyT
          New Member
          • Apr 2007
          • 4

          #5
          Pretty much everything, kinda have no clue on how to code a menu :/

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Try an infinite loop:

            Code:
            while (1)
            {
                  cin >> choice;
                  case 1:
                      Add(...);
                      break;
                  case 2:
                      Revise(...);
                      break;
                  case 3:
                      Exit();
                      return 0;
            }

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              Originally posted by JeremyT
              Pretty much everything, kinda have no clue on how to code a menu :/
              Ok, well then, let's start with the basics: do you know how to print stuff out and read variables in?

              Do you have your functions created? Do you know how to call them? Have you tested them and know that they work?

              Comment

              • ilikepython
                Recognized Expert Contributor
                • Feb 2007
                • 844

                #8
                Originally posted by JeremyT
                Pretty much everything, kinda have no clue on how to code a menu :/
                You can have a series of cout statements that explain the options and then have a number correspond to each option like:
                1: first option
                2: second option
                etc.
                then check what number the user entered and perform the correct function.

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  Oops. forgot the switch

                  Try an infinite loop:

                  Code:
                  while (1)
                  {
                        cin >> choice;
                        switch(choice)
                        {
                        case 1:
                            Add(...);
                            break;
                        case 2:
                            Revise(...);
                            break;
                        case 3:
                            Exit();
                            return 0;
                        }
                  }

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    Originally posted by weaknessforcats
                    Try an infinite loop:

                    Code:
                    while (1)
                    {
                          cin >> choice;
                          case 1:
                              Add(...);
                              break;
                          case 2:
                              Revise(...);
                              break;
                          case 3:
                              Exit();
                              return 0;
                    }
                    I wouldn't recommend an infinite loop, but that's a personal preference, I don't like break statements. I'd suggest having a sentinel/exit value to check (have one of the cases be 'exit' and set a boolean, so the while will fail).

                    But as I said, that's personal preference, weaknessforcats ' method will certainly work.

                    Comment

                    • JeremyT
                      New Member
                      • Apr 2007
                      • 4

                      #11
                      Yea most of the functions work, and finally got it done recently. Thanks guys!

                      Comment

                      Working...