user1832076
user1832076

Reputation: 57

Using a q to quit the program

asking the user after the table has been output to input a number of widgets. You should then calculate the cost and output the value. If the user enters ‘q’ or ‘Q’, the program should terminate

what code could I use to quit the program?

Upvotes: 1

Views: 1136

Answers (2)

Servy
Servy

Reputation: 203802

You shouldn't use any specific code to quit the program at all. Some methods exist, but they should be reserved for exceptional circumstances. (This isn't an exceptional circumstance.)

What you should do is simply keep the program running as long as they don't want to quit. Many console programs will end up with a loop such as this:

string userInput = Console.ReadLine();

while(userInput != quitCommand)
{
    //Do stuff with user input

    userInput = Console.ReadLine();
}

//end of program.

Whenever possible (and it's quite possible here) your program should end simply because the call to your Main method reached the end, normally.

Upvotes: 4

Adriano Carneiro
Adriano Carneiro

Reputation: 58595

number of ways to do that:

Application.Exit;

or

System.Environment.Exit( exitCode );

It really depends on your environment, which you did not specify.

Upvotes: 5

Related Questions