Press Y to re-run program and E to exit. How do I do this in C#
Go to solution
Solved by neystro,
you need to do a verification in 2 step:
first you check until the user enter a valid letter (y or e in your case) and then with the valid letter you receive, you can chose to restart or to exit.
ex:
do
{
// your code...
Console.WriteLine("Press 'e' to exit or 'y' to perform another conversion");
yesNo = Console.ReadLine().ToLower();
while(!yesNo.Equals("y") && !yesNo.Equals("e")){
Console.WriteLine("Invalid!");
Console.WriteLine("Press 'e' to exit or 'y' to perform another conversion");
yesNo = Console.ReadLine().ToLower();
}
}while (yesNo.Equals("y"));
// if your app arrive here: it mean that the user enter e
Application.Exit();
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now