C# noob with a little problem here

  • Topic: C# 
  • Thread starter stonecoldgen
  • Start date
  • Tags Tags
    Noob
2 replies · 2K views · last reply
stonecoldgen
Messages
108
Reaction score
0
Hi, so I have this code:


Code:
namespace Program1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Is the numer less than 10?");

      

            int numero = Console.Read();

            if (numero < 10)
            {
                Console.WriteLine("true");
            }
            else
            {
                Console.WriteLine("false");
            }

           

        }
    }
}




The console is always writing the line "false" even if I input a number that should return "true."


any idea what am I doing wrong?
 
maybe you have to cast the input into an integer as it comes in, else it converts to integer zero
 
Console.Read returns the ascii code for the key pressed, not the number itself.

Try this:
Code:
            int numero = Int32.Parse(Console.ReadLine());