rogerzebra
Technical User
Hi All,
I get an error with this code even though is a sample straight out from the book "Start with C#". This should be a fairly simple error but i'm new to C# programming. The issue I have is that it does executing when I'm using an integer for var1 and var2, so a whole number works fine but the purpose of converting the var1 & var2 to double,is to use decimals and when I does it trows me the error "Input string was not in a correct format." Could anyone see why this is not working, that would be much appreciated. Thanks so much
/R
I get an error with this code even though is a sample straight out from the book "Start with C#". This should be a fairly simple error but i'm new to C# programming. The issue I have is that it does executing when I'm using an integer for var1 and var2, so a whole number works fine but the purpose of converting the var1 & var2 to double,is to use decimals and when I does it trows me the error "Input string was not in a correct format." Could anyone see why this is not working, that would be much appreciated. Thanks so much
/R
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace Ch04Ex02
{
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);
}
}
}