0

I am trying to create a function that displays the Height of a person according to the user input, either short, average, or tall. If the user enters something else, displays "Abnormal" The problem here is that I'm only getting Abnormal as a result for all input.

using System;

       public class program
        {
            public static void Main()
            {

                int a;

               Console.WriteLine("Enter the Height: ");
                a = Convert.ToInt32(Console.ReadLine());
    switch (a) 
    {
      case 1:
             if (a < 150)
        Console.WriteLine("Short");
        break;
      case 2:
            if ((a >= 150) && (a <= 165))
        Console.WriteLine("Average");
        break;
      case 3:
            if ((a >= 166) && (a <= 195))
        Console.WriteLine("Tall");
        break;

      default:
      Console.WriteLine("Abnormal");
       break;
    }

 }


 }
Vishav Premlall
  • 456
  • 6
  • 22
  • this isn't javascript ... but your case statement only allows a to be 1, 2 or 3 otherwise you get the default ... so, how can a be 3 AND greater than 150 for example ... it can only be one of those - you don't need switch/case at all – Jaromanda X Apr 28 '20 at 03:54
  • 5
    `case 1` doesn't mean 'this is the first scenario'. It means 'a is exactly 1'. – mjwills Apr 28 '20 at 04:01

0 Answers0