zhongdazui 2015-02-08 15:36 采纳率: 62.5%
浏览 1625
已采纳

关于if-else if。菜菜鸟弱弱的提问

Console.WriteLine("你的年龄为?");
int age = Convert.ToInt32(Console.ReadLine());
if (age >= 18)
{ Console.WriteLine("你可以查看有关内容。"); }
else if (age < 10)
{ Console.WriteLine("抱歉,你不能查看相关内容。"); }
else
{
Console.WriteLine("你是否要继续查看?yes/no");
if (Console.ReadLine() == "yes")
{ Console.WriteLine("请查看相关内容。"); }
else if (Console.ReadLine() == "no")
{ Console.WriteLine("你放弃查看相关内容。程序退出。"); }
}

        Console.ReadKey();


                    加粗的部分是有错误吗?因为我输入一次no ,没反应,第二次输入no,程序才正常往下走。![图片说明](https://img-ask.csdn.net/upload/201502/08/1423409712_342742.jpg)
  • 写回答

3条回答 默认 最新

  • threenewbee 2015-02-08 15:38
    关注

    有错误,这样会读取两次,应该这么写:
    string input = Console.ReadLine();
    if (input == "yes")
    { Console.WriteLine("请查看相关内容。"); }
    else if (input == "no")
    { Console.WriteLine("你放弃查看相关内容。程序退出。"); }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据