JOSHUA THORPE
JOSHUA THORPE

Reputation: 41

Yes or No Confirmation in C# Console

I have been learning some C# over the last day or so. I've finished the first few tutorials that covered strings and numbers.

I was wondering if someone could explain how to create a yes or no confirmation message?

If the answer is no, I would like it to loop back to the first line of questioning. If yes, well I haven't worked that part out yet :P I hope to read and learn more so I can keep adding to it.

using System;

namespace Digimon
{
    class Program
    {
        static void Main(string[] args)
        {
            string YourName = ""; string DigimonName = ""; string DigimonGender = "";
            Console.WriteLine("Welcome to Digimon World.\r");
            Console.WriteLine("created by Raw\n");

            //Ask for the digidestines name.
            Console.WriteLine("Jijimon: What is your name?");
            YourName = (Console.ReadLine());

            //Ask for the digimons name. 
            Console.WriteLine($"Jijimon: Great {YourName}, what is your Digimon's name?");
            DigimonName = (Console.ReadLine());

            //Ask for its sex.
            Console.WriteLine("Jijimon: Is it a boy or a girl?");
            DigimonGender = (Console.ReadLine());

            //Confirm details given in intro.
            Console.WriteLine($"Jijimon: Okay {YourName}, so your Digimon's a {DigimonGender} and its name is {DigimonName}?");
        }
    }
}

Thank you all very much in advance.

Upvotes: 3

Views: 886

Answers (1)

Oyeme
Oyeme

Reputation: 11225

Try

while (true)
{
    Console.WriteLine("Welcome to City Mail.");

    string YourName = ""; string DigimonName = ""; string DigimonGender = ""; Console.WriteLine("Welcome to Digimon World.\r"); Console.WriteLine("created by Raw\n");
    //Ask for the digidestines name.
    Console.WriteLine("Jijimon: What is your name?");
    YourName = (Console.ReadLine());

    //Ask for the digimons name. 
    Console.WriteLine($"Jijimon: Great {YourName}, what is your Digimon's name?");

    DigimonName = (Console.ReadLine());

    //Ask for its sex.
    Console.WriteLine("Jijimon: Is it a boy or a girl?");
    DigimonGender = (Console.ReadLine());

    //Confirm details given in intro.
    Console.WriteLine($"Jijimon: Okay {YourName}, so your Digimon's a {DigimonGender} and its name is {DigimonName}?");

    Console.WriteLine("Is this correct? (Y)es (N)o");
    ConsoleKeyInfo yesNo = Console.ReadKey(true);

    // if 'y' key is pressed
    if (yesNo.Key == ConsoleKey.Y)
    {
        Console.WriteLine("Exit and do something else..");
        break;
    }
}

Upvotes: 1

Related Questions