| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1544 人关注过本帖
标题:输入空值没有效果,是哪出错了,请教各位大哥
取消只看楼主 加入收藏
play789
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-8-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
输入空值没有效果,是哪出错了,请教各位大哥
using System;
using System.Collections.Generic;
using System.Text;

namespace Project1
{
    class Class1
    {
        static void Main()
    {
        bool myBool = false;
        Console.WriteLine("请输入姓名");
        Console.WriteLine("(1)张三(2)李四(3)王五");
        int myName =Convert.ToInt32( Console.ReadLine().Trim());
        Console.WriteLine("请输入密码");
        string myPassword=Console.ReadLine().Trim();
        do
    {
        
        switch(myName)
    {
        case 1:
        if(myPassword=="123456")
    {
        Console.WriteLine("密码正确!");
    }
    else
    {
    Console.WriteLine("密码错误");
    }
    break;
    case 2:
    if(myPassword=="234567")
    {
        Console.WriteLine("密码正确!");
    }
    else
    {
    Console.WriteLine("密码错误");
    }
    break;
   case 3:
    if(myPassword=="345678")
    {
        Console.WriteLine("密码正确!");
    }
    else
    {
    Console.WriteLine("密码错误");
    }
    break;
   default:
   Console.WriteLine("查无此人");
   break;
}
}
   while(!myBool);
        Console.WriteLine("没有输入有效姓名,系统将退出……\n按回车键退出程序!");
        Console.ReadLine();
}
}
}
搜索更多相关主题的帖子: 出错 
2009-08-13 05:01
play789
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-8-13
收藏
得分:0 
答案找到了,加个if{}else{}就可以了!

using System;
using System.Collections.Generic;
using System.Text;
 
namespace Project1
{
    class Class1
    {
        static void Main()
        {
   
            Console.WriteLine("请输入姓名");
            Console.WriteLine("(1)张三(2)李四(3)王五");
            string myName = Console.ReadLine().Trim();
            if (myName = string.Empty)
            {
                Console.WriteLine("没有输入有效姓名,系统将退出……\n按回车键退出程序!");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("请输入密码");
                string myPassword = Console.ReadLine().Trim();
                switch (myName)
                {
                    case "1":
                        if (myPassword == "123456")
                        {
                            Console.WriteLine("密码正确!");
 
                        }
                        else
                        {
                            Console.WriteLine("密码错误");
                        }
                        break;
                    case "2":
                        if (myPassword == "234567")
                        {
                            Console.WriteLine("密码正确!");
                        }
                        else
                        {
                            Console.WriteLine("密码错误");
                        }
                        break;
                    case "3":
                        if (myPassword == "345678")
                        {
                            Console.WriteLine("密码正确!");
                        }
                        else
                        {
                            Console.WriteLine("密码错误");
                        }
                        break;
                    default:
                        Console.WriteLine("查无此人");
                        break;
                }
            }
        }
    }
}
2009-08-13 05:57
快速回复:输入空值没有效果,是哪出错了,请教各位大哥
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011470 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved