本帖最后由 月儿圆 于 2013-6-16 00:32 编辑
如下:是在视频中学的,自己想到的,但是总是觉得程序不够简化,谁能优化一下?问题是进入if条件后不能继续上面的while循环了
- <P>bool flag = false;
- Console.WriteLine("这道题你会了吗(y/n)");
- string answer = Console.ReadLine();
- answer = answer.ToLower();
- int i = 0;
- while (answer == "n" && i < 10)
- {
- Console.WriteLine("老师讲一下");
- Console.WriteLine("这道题你会了吗(y/n)");
- answer = Console.ReadLine();
- answer = answer.ToLower();
- i++;
- }
- if (answer == "y")
- {
- Console.WriteLine("好聪明你们可以放学了");
- flag = true;
- }
- if (answer != "n" && answer != "y")
- {
- Console.WriteLine("输入有误,请重新输入");</P>
- <P>answer = Console.ReadLine();
- answer = answer.ToLower();
- flag = true;
- }
- if (flag == false)
- {
- Console.WriteLine("讲了十遍还不会?!放学吧!明天再讲!!!");
- }
- Console.ReadKey();
- </P>
复制代码 |