首页 > 解决方案 > 为什么我的代码会给出“异常”作为结果

问题描述

我正在尝试创建一个函数,该函数根据用户输入(短、平均或高)显示人的身高。如果用户输入其他内容,则显示“异常”这里的问题是我只得到异常作为所有输入的结果。

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;
    }

 }


 }

标签: c#

解决方案


推荐阅读