就这个要求我不会了:
   使用while循环语句,依次读取输入的数值,计算各数之和保存在变量total中,并在变量count中记录输入的个数,当用户输入x或X时跳出循环
--------------------------------------------------------------------------------------------------------------------
希望大家帮忙,感激不尽!
------------------------------------------//这个是我写的小程序,但是没有上面的那个(当用户输入x或X时跳出循环)功能、
          static void Main(string[] args)
        {
            Int32 count = 0;
            float total = 0;
            string s_input;
            bool condition = true; //这个是我临时测试自己程序是否错误的哨兵            Console.WriteLine("Please Put Into Swatch Every Time !\n");
            Console.WriteLine("total == {0}", total.ToString());
            Console.WriteLine("count == {0}", count.ToString());
            Console.WriteLine("-------------------------------------\n");
            
            while (condition)
            {
                if (count == 4)  //这个是我临时测试自己程序是否错误的哨兵
                    condition = false;
                else
                {
                    s_input = Console.ReadLine();
                    total += Convert.ToInt32(s_input);
                    count++;
                    Console.WriteLine("total == {0}", total.ToString());
                    Console.WriteLine("count == {0}", count.ToString());
                }
            }
            Console.WriteLine("The Number Is {0}\n", (total / count));
        }

解决方案 »

  1.   

        s_input   =   Console.ReadLine(); 
        if (s_input=="x" || s_input == "X")
            break;
        total   +=   Convert.ToInt32(s_input); 或者用这个
        if (s_input.Equals("x") || s_input.Equals("X"))
            break;
      

  2.   

    这问题真无聊...等球赛开始更无聊...
    //Int32 count = 0;
    //改成int别名...统一风格...
    int count = 0;
    float total = 0;
    string s_input;
    bool condition = true;Console.WriteLine("Please Put Into Swatch Every Time:\n");
    //Console.WriteLine("total == {0}", total.ToString());
    //Console.WriteLine("count == {0}", count.ToString());
    //上面两句有用吗?人人都知道是0
    //Console.WriteLine("-------------------------------------\n");while (condition)
    {
        s_input = Console.ReadLine();
        //total += Convert.ToInt32(s_input);
        //ToInt32只保留整数...改用TryParse避免异常...
        float tmp = 0;
        if (float.TryParse(s_input, out tmp))
        {
            total += tmp;
            count++;
            Console.WriteLine("total == {0}", total.ToString());
            Console.WriteLine("count == {0}", count.ToString());
        }
        else
        {
            //退出循环条件
            condition = (s_input.Trim().ToLower() != "x");
        }
    }
    Console.WriteLine("The Number Is {0}\n", (total / count));
      

  3.   

    try
    {
        total   +=   Convert.ToInt32(s_input); 
        count++; 
    }
    catch
    {
        Console.WriteLine("Numbers only.");
    }