Ive just started learning C# with VFisual Basic 2010 and this is only the second program lol..! I know is very similar to JAVA but im not doing something right...!
Can anyone tell me why this is not reading 'if (num <= 9)'.... for some reason when I Debug, if I input a 9, num becomes 57 and so obviously jumps to the 'else if'.
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NumberRange
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please input a number.");
int num = Console.Read();
if (num <= 9)
{
Console.WriteLine("This number is within the specified range.");
}
else if (num > 9)
{
Console.WriteLine("Sorry, this number is out of range.");
Console.WriteLine("Please try another.");
}
}
}
}