C# noob with a little problem here

  • Context: C# 
  • Thread starter Thread starter stonecoldgen
  • Start date Start date
  • Tags Tags
    Noob
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
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?
 
Physics news on Phys.org
Console.Read returns the ascii code for the key pressed, not the number itself.

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