vendredi 7 mai 2021

Having trouble with a basic C# if/else statement in Visual Studio [duplicate]

I've been trying to transfer what I learned in a college class about Visual Basic into C#, and I'm having an issue trying to get the else part of my statement to show up instead of the if. Here's what I'm trying to deal with. It's a basic console app, the purpose is to tell a person who enters their age if they are an adult or not.

using System;

namespace CSharpConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {

            int iNumber = 0;

            Console.Write("Input your age: ");
            iNumber = Console.Read();

            if (iNumber >= 18)
            {

                Console.Write("You are an adult!");

            }    
            else
            {

                Console.WriteLine("You are not an adult!");

            }    
        

            Console.ReadKey();

       

        }
    }
}

When I try and enter a value below 18, I get stuck with "You are an adult!" instead of "You are not an adult!" I appreciate any help!

Aucun commentaire:

Enregistrer un commentaire