问答详情
源自:3-6 C#中多重if结构

帮忙看看哪里错了,查了很久了?

using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string job = "科员";
            if (job == "局长")
            {
                Console.WriteLine("发双黄月饼");
            }
            else if (job == "处长")
            {
                Console.WriteLine("发蛋黄月饼");
            }
            else if(job =="科长")
            {
                Console.WriteLine("发枣泥月饼");
            }
            else
            {
                Console.WriteLine("发五仁月饼");
            }
        }
    }
}

提问者:weixin_慕先生1490638 2021-11-28 18:32

个回答

  • 紫色的秋
    2023-05-10 09:29:57

    好像是对的,看看运行报错的地方,可能是标点的中文字符。

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                string job = "科员";
                if (job == "局长")
                {
                    Console.WriteLine("发双黄月饼");
                }
                else if (job == "处长")
                {
                    Console.WriteLine("发蛋黄月饼");
                }
                else if (job == "科长")//请输入
                {
                    Console.WriteLine("发枣泥月饼");
                }
                else//请输入
                {
                    Console.WriteLine("发五仁月饼");
                }
            }
        }
    }

    我的运行成功了

  • weixin_宝慕林8217622
    2022-04-21 17:26:21

    没有声明数组