A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

©   /  2013-7-26 16:12  /  1758 人查看  /  12 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 小天 于 2013-7-30 23:47 编辑

出错原因:当进行最后一个if判断的时候,条件为假,执行else中的语句所以输出了一个a,又输出一个e

if-else if和switch都可以处理分支结构
区别:if-else if可以处理范围,switch只能处理整数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {         
Console.WriteLine("输入结业成绩");
try{
            int input3 = Convert.ToInt32(Console.ReadLine());
            if (input3 > 100 || input3 < 0)
            {
                Console.WriteLine("输入的数据有误(只能输入0-100之间的数),程序结束");
            }
            else  if (input3 >= 90)
            {
                Console.WriteLine("a");
            }
            else  if (input3 >= 80)
            {
                Console.WriteLine("b");
            }
            else  if (input3 >= 70)
            {
                Console.WriteLine("c");
            }
            else   if (input3 >= 60)
            {
                Console.WriteLine("d");
            }
            else
            {
                Console.WriteLine("e");
            }
}
             catch{
              Console.WriteLine("数据有误,程序结束");
                 }
            Console.ReadKey();
        }
    }
}


回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马