jeudi 26 décembre 2019

C#: After running program and the input is answered with an if statement, how do i get the program to keep asking the question?

I asked a question in the WriteLine form that requires a numbered input, converted it to an int, used that int in an if-else, and I want the question to be re-asked afterward. Any idea?

Example:

Console.WriteLine("What hour is it?: ");
int hour = Convert.ToInt32(Console.ReadLine());

if (hour > 0 && hour < 12)
{
    Console.WriteLine("It's morning.");
}

if (hour > 12 && hour < 18)
{
    Console.WriteLine("It's evening.");
}
else if (hour > 18 && hour < 24)
{
    Console.WriteLine("It's night.");
}
else
{
    Console.WriteLine("Invalid Input.");
}

Aucun commentaire:

Enregistrer un commentaire