Compare 2 numbers and get the result which is greater

Karthikanbarasan
Posted by Karthikanbarasan under Regular Expressions category on | Points: 40 | Views : 2900
This code gets the users inputs in a console and check the greater of the 2 numbers

class Program
{
static void Main(string[] args)
{
string comparison;
Console.WriteLine("Enter a number:");
double var1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter another number:");
double var2 = Convert.ToDouble(Console.ReadLine());
if (var1 < var2)
comparison = "less than";
else
{
if (var1 == var2)
comparison = "equal to";
else
comparison = "greater than";
}
Console.WriteLine("The first number is {0} the second number.",
comparison);
Console.ReadKey();
}
}

Comments or Responses

Login to post response