Click here to Skip to main content
15,850,921 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Wa
    {
        public void start()
        {

            int choice = -1;

            while (choice != 0)
            {
                WriteMenuText();
                choice = int.Parse(Console.ReadLine());
                {
                }
            }
        }

        public void WriteMenuText()
        {
            Console.WriteLine("\n1 Bin 2");
            Console.WriteLine("2 Bin 2 ");
            Console.WriteLine("0 Exit the program");
            Console.WriteLine("\nYour choice");
            Bin1();
            Bin2();
        }

        private void Bin1()
        {

        }
        private void Bin2()
        {

        }
    }
}


When the program start I want the menu to come up first and not the menu and the text in bin 1 to. And how do I do it like when I press 1 the bin1 will come up and press 2 bin 2 will come up?
Posted
Updated 2-Feb-12 8:18am
v2
Comments
RDBurmon 2-Feb-12 12:56pm    
Hello Kalle ,
Could you please elaborate more ?
Let me ask some question to you.
Your current out put is like

1 Bin 2
2 Bin 2
0 Exit the program

Your choice

and as you have already specified this is not the output you want .

Please specify here by showing menu you want.
Please do it in a way I represent the out put above.

Helps a lot.
--Rahul D.
Kalle_5 2-Feb-12 13:02pm    
If i typ in private void Bin1()
console.write("hello");

when i com to the menu it will show.
1 Bin 2
2 Bin 2
0 Exit the program
Your choice
Hello

that i want is when it start it will do:
1 Bin 2
2 Bin 2
0 Exit the program
Your choice
And then when i pick 1 it will show hello and the menu will com up again
Sergey Alexandrovich Kryukov 2-Feb-12 13:34pm    
Not a question, despite of a question mark. What is your problem? How to write "if", "switch", enumeration (yes, enumeration type, not 1, 2, 3)? what?
The answer would be "write exactly what you want".
--SA

1 solution

you need to rewrite ur code
C#
<pre lang="cs">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Wa
    {
        public void start()
        {

            int choice = -1;

            while (choice != 0)
            {
                WriteMenuText();
                choice = int.Parse(Console.ReadLine());
                {
                 //add these  lines
                 if(choice==1)
                   Bin1();
                 else
                   Bin2();
                }
            }
        }

                public void WriteMenuText()

        {
            Console.WriteLine("\n1 Bin 2");
            Console.WriteLine("2 Bin 2 ");
            Console.WriteLine("0 Exit the program");
            Console.WriteLine("\nYour choice");
           // Bin1(); 
         //   Bin2();
          //remove above 2 lines
                }

        private void Bin1()
        {

        }
        private void Bin2()
        {

        }
    }
}
 
Share this answer
 
Comments
Kalle_5 2-Feb-12 13:08pm    
thx for it but the menu will not come back when i pick 1 or 2
Sergey Alexandrovich Kryukov 2-Feb-12 13:38pm    
Again, what help do you need? How to write loop?
You never said you need anything "come back" before.
--SA
Silent Guardian 2-Feb-12 13:25pm    
whats present in bin1 and bin2?
menu is not displayed bcoz bin1 /bin2 is not returning.
Kalle_5 2-Feb-12 13:38pm    
i try it out so i have
console.write("hello");

do i only need to put
return; on the end?
Sergey Alexandrovich Kryukov 2-Feb-12 13:42pm    
(Sigh...) Not that your code is beyond repair, you are. You really need to start learning some programming basics from scratch, otherwise no one could help you. Start over, come back when you know how basic things work: method, instance, method parameters, return, calls, loops and control structures. Will three days of reading be enough? :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900