Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am currently doing an assignment for one of my programming units and I am required to use switch statements do display a menu and collect data. I seem to have worked out the switch statement itself, but I am wondering how I return the user to the menu once a case has executed?

For example :

Console.writeline("Enter Customer Details (s) "); 
Console.writeline("Enter usage data (u) "); 
Console.writeline("Display usage data (d) "); 

menu = console.readline();

switch (menu) 
 case 's':
 statement 
 break;

 case 'u':
 statement 
 break; 

 case 'd':
 statement 
 break; 

 default : 
 statement
 break;

Now, let's say the user wants to enter the Usage data first, how do I return them to the 'menu' so they can opt to enter customer details and/or display the data.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
295 views
Welcome To Ask or Share your Answers For Others

1 Answer

As I said in the comments, you could embed it in a while loop

bool continue = true;

while (continue)
{
    Console.WriteLine("Enter Customer Details (s)"); 
    Console.WriteLine("Enter usage data (u)"); 
    Console.WriteLine("Display usage data (d)");
    Console.WriteLine("Exit (e)");

    string menu = Console.ReadLine();

    switch (menu)
    {
        case "s":
            //statement 
            break;

        case "u":
            //statement 
            break; 

        case "d":
            //statement 
            break; 

        case "e":
        default: 
            continue = false;
            break;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...