回 帖 发 新 帖 刷新版面

主题:[求助]请问大家!下列的代码那里有错,谢谢!

请问大家!下列的代码那里有错,谢谢!

[size=2]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int k = int.Parse(textBox1.Text);
            switch(k/10)
            {[color=FF0000]_[/color]
            case0:
            case1:
            case2:
            case3:
            case4:
            case5:
                textBox2.Text="不及格";
                break;
            case6:
                textBox2.Text="及格";
                break;
            case7:
                textBox2.Text="中等";
                break;
            case8:
                textBox2.Text="良好";
                break;
            case9:
            case10:
                textBox2.Text="优秀";
                break;
            default;[color=FF0000]_[/color]
                MessageBox.Show("成绩输入错误,请重新输入!");
                break;[color=FF0000]_[/color]
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}[/size]
上边有红色的_都是系统提出有错误的地方,老说要加上"}""{"我找了很久也找不到结果,请大家们帮手看看!

回复列表 (共2个回复)

沙发

//修改后:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int k = int.Parse(textBox1.Text);
            switch(k/10) //switch 书写错误
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                textBox2.Text="不及格";
                break;
            case 6:
                textBox2.Text="及格";
                break;
            case 7:
                textBox2.Text="中等";
                break;
            case 8:
                textBox2.Text="良好";
                break;
            case 9:
            case 10:
                textBox2.Text="优秀";
                break;
            default:
                MessageBox.Show("成绩输入错误,请重新输入!");
                break; //这里其实没有必要加 break
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

板凳

default:

我来回复

您尚未登录,请登录后再回复。点此登录或注册