这是一道用C#做的选择题,问题在于,我现在输入一个答案,显示结果后,再想继续输入就直接退出

[复制链接]
查看11 | 回复4 | 2011-3-20 21:48:58 | 显示全部楼层 |阅读模式
我想输入错误时继续输入,知道输入正确为止再退出 怎么办!
using System;
using System.Collections.Generic;
using System.Text;
namespace 作业
{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("你知道计算机键盘上有多少个键吗?");

Console.WriteLine("A 105");

Console.WriteLine("B 106");

Console.WriteLine("C 107");

Console.WriteLine("D 108");

string s = Console.ReadLine();



if (s == "A") { Console.WriteLine("选择错误!"); }
else if (s == "B") { Console.WriteLine("选择错误!"); }
else if (s == "C") { Console.WriteLine("选择错误!"); }
else if (s == "D") { Console.WriteLine("选择正确!"); }

Console.ReadKey();
}

}
}

回复

使用道具 举报

千问 | 2011-3-20 21:48:58 | 显示全部楼层
while (true){.......写出题目 Console.WriteLine("请输入答案!\r\n");var key=Console.ReadKey();bool isRight=false;switch(key){......判断输入case:.正确的时候isRight=true;break;default:isRight=false;}if(isRight){Console.WriteLine("选择正确!");break;如果回答正确,中断循环,继续下一题}else{Console.WriteLine("选择错误!,请重试"); }}
回复

使用道具 举报

千问 | 2011-3-20 21:48:58 | 显示全部楼层
把if那一大坨改成while(s!="D") Console.WriteLine("选择错误!"); Console.WriteLine("选择正确!");
回复

使用道具 举报

千问 | 2011-3-20 21:48:58 | 显示全部楼层
写一个死循环在外面,直到输入正确为止
回复

使用道具 举报

千问 | 2011-3-20 21:48:58 | 显示全部楼层
把if那一大坨改成while(s!="D") Console.WriteLine("选择错误!"); Console.WriteLine("选择正确!");
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行