In: Computer Science
I need this written in C # ASAP
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.
Please find the code , output below.
using System;
class Name {
static void Main() {
string firstname , lastname;
char ans='Y';
Console.WriteLine("Do you want to enter a name (Y/N)?");
ans=Console.ReadLine()[0];
while(ans=='y' || ans == 'Y'){
Console.WriteLine("Enter First and Last Name:");
firstname=Console.ReadLine();
lastname=Console.ReadLine();
Console.WriteLine("Your name is "+firstname+" "+lastname);
Console.WriteLine("Do you want to enter a name (Y/N)?");
ans=Console.ReadLine()[0];
}
}
}