class Program

    {class Program
    {
        static void Main()
        {
          int TotalCoffeCost = 0;

          Start:
          Console.WriteLine("**Caffe Menu**\n\n1-Small = 1$, \n2-Medium =2$, \n3-Large");
          Console.WriteLine("-------------------------------------------------------------");

            int UserChoice = int.Parse(Console.ReadLine());



          switch (UserChoice)
          { 
              case 1:
                  TotalCoffeCost += 1;
                  break;

              case 2:
                  TotalCoffeCost += 2;
                  break;
              case 3:
                  TotalCoffeCost += 3;
                   break;
              default:
                  Console.WriteLine("Your Choice is invalid please select the order numbers");
                  goto Start;
          }
               Decide:
              Console.WriteLine("Do you want to buy another coffe - Yes or No");
              string UserDecision = Console.ReadLine();

              switch (UserDecision.ToUpper())
              { 
                  case "YES":
                      goto Start;
                  case "NO":
                      break;
                  default:
                      Console.WriteLine("Your choice {0} is invalid please try again", UserDecision);
                      goto Decide;
              }


              Console.WriteLine("Thanks for shoping with us");
              Console.WriteLine("Bill Amount= {0}$",TotalCoffeCost );

        }
    }


    static void Main()
    {
      int TotalCoffeCost = 0;

      Start:
      Console.WriteLine("**Caffe Menu**\n\n1-Small = 1$, \n2-Medium =2$, \n3-Large");
      Console.WriteLine("-------------------------------------------------------------");

        int UserChoice = int.Parse(Console.ReadLine());



      switch (UserChoice)
      { 
          case 1:
              TotalCoffeCost += 1;
              break;

          case 2:
              TotalCoffeCost += 2;
              break;
          case 3:
              TotalCoffeCost += 3;
               break;
          default:
              Console.WriteLine("Your Choice is invalid please select the order numbers");
              goto Start;
      }
           Decide:
          Console.WriteLine("Do you want to buy another coffe - Yes or No");
          string UserDecision = Console.ReadLine();

          switch (UserDecision.ToUpper())
          { 
              case "YES":
                  goto Start;
              case "NO":
                  break;
              default:
                  Console.WriteLine("Your choice {0} is invalid please try again", UserDecision);
                  goto Decide;
          }


          Console.WriteLine("Thanks for shoping with us");
          Console.WriteLine("Bill Amount= {0}$",TotalCoffeCost );

    }
}

This is what i have done so far, i need when app starts to ask me to press enter F for Food and D for Drinks, i know already how to make menus for drinks and food like i did for coffes. please help and sorry about my english is not my native laguage. thank you 

Recommended Answers

All 2 Replies

The first thing to do is put the code for coffee into a sub routine and call it from main. Once this is done you're ready to put your front end menu in main and make more sub routines to call based on the choices in main.

    class Program
    {
        static void Main()
        {
            BuyCoffee();
        }
        static void BuyCoffee()
        {
            int TotalCoffeCost = 0;
        Start:
            Console.WriteLine("**Caffe Menu**\n\n1-Small = 1$, \n2-Medium =2$, \n3-Large");
            Console.WriteLine("-------------------------------------------------------------");
            int UserChoice = int.Parse(Console.ReadLine());
            switch (UserChoice)
            {
                case 1:
                    TotalCoffeCost += 1;
                    break;
                case 2:
                    TotalCoffeCost += 2;
                    break;
                case 3:
                    TotalCoffeCost += 3;
                    break;
                default:
                    Console.WriteLine("Your Choice is invalid please select the order numbers");
                    goto Start;
            }
        Decide:
            Console.WriteLine("Do you want to buy another coffe - Yes or No");
            string UserDecision = Console.ReadLine();
            switch (UserDecision.ToUpper())
            {
                case "YES":
                    goto Start;
                case "NO":
                    break;
                default:
                    Console.WriteLine("Your choice {0} is invalid please try again", UserDecision);
                    goto Decide;
            }
            Console.WriteLine("Thanks for shoping with us");
            Console.WriteLine("Bill Amount= {0}$", TotalCoffeCost); 
        }
    }

}

If you keep the code in main to a minimum this will go a long way to uncluttering your code. Also as your coding keep an eye out for sections of code you keep repeating. Try and split them out to a sub routine. One advantage to this is, if you have to make a change, it will be needed in as few places as possible. Also this allows you to work on one section at a time. As each section is done you move on to the next.

commented: well explained +14

Try to keep the use of goto to a strict minimum. The way that it is used in your code is nice and clean, but we don't want to return to spagetti code BASIC I hope.
There is also this snippet with an example of how you could code a menu.
But perhaps you have not studied looping yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.