In: Computer Science
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
C# code:
using System;
class Program {
static void Main() {
      //initializing name
      string name;
      //asking if they want to enter
name
      Console.Write("Do you want to enter
a name (Y/N)? ");
      //asking for choice
      string
choice=Console.ReadLine();
      //looping till choice is y or
Y
      while(choice=="y" ||
choice=="Y"){
          //asking for
First and Last name
           
Console.Write("Enter First and Last Name: ");
           
//accepting it
           
name=Console.ReadLine();
           
//printing it
           
Console.WriteLine(name);
           
//asking if they want to enter name
           
Console.Write("Do you want to enter a name (Y/N)? ");
           
//asking for choice
           
choice=Console.ReadLine();
      }
}
}
Screenshot:

Input and Output:
