C#程序设计:给出十道两位数的四则运算的题目,每道题10分,学生输入该题的答案,计算机根据学生的答案判

(接上)正确与否,当结束时给出成绩。(用Random类产生两个两位数的随机数)... (接上)正确与否,当结束时给出成绩。(用Random类产生两个两位数的随机数) 展开
 我来答
cdinten
2011-04-01 · TA获得超过6588个赞
知道大有可为答主
回答量:3562
采纳率:56%
帮助的人:1298万
展开全部
一会给你完整代码
using System;
using System.Collections;

namespace Castor
{
class Program
{
static void Main(string[] args)
{
int right = 0;
for (int i = 0; i < 10; i++)
{
Random rd = new Random();
int a = rd.Next(10, 99);
int b = rd.Next(10, 99);
int op = rd.Next(1, 4);
char c='+';
int result = 0;
switch (op)
{
case 1: c = '+'; result = a + b; break;
case 2: c = '-'; result = a - b; break;
case 3: c = '*'; result = a * b; break;
case 4: c = '/'; result = a / b; break;
}
//Console.WriteLine(a.ToString() + op.ToString() + b.ToString());
Console.WriteLine("第{0}题:{1}{2}{3}=?", i+1, a, c, b);
long answer=Convert.ToInt16(Console.ReadLine());
if (answer == result)
right++;
}
Console.WriteLine("你答对了{0}道题", right);
Console.Read();
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qiang300
2011-04-01 · TA获得超过117个赞
知道小有建树答主
回答量:711
采纳率:100%
帮助的人:288万
展开全部
pubilc void MethodMain()
int numberA = 0;
int numberB = 0;
string res = string.Empty;
int socre = 0;
Random random = new Random(1);
for (int i = 0; i < 10; i++)
{
numberA = random.Next(10, 100);
numberB = random.Next(10, 100);
int operation = random.Next(0, 4);
if (operation == 3 && numberB == 0)
{
i--;
continue;
}
string[] result = MetodA(numberA, numberB, operation);
Console.WriteLine(result[0]);
Console.WriteLine(string.Format("第{0}题请输入答案", i + 1));
res = Console.ReadLine();
while (res.Trim().Length == 0)
{
Console.WriteLine("请输入答案");
res = Console.ReadLine();
}
try
{
decimal.Parse(res.Trim());
}
catch
{
Console.WriteLine("请输入数字");
res = Console.ReadLine();
}
if (decimal.Parse(res.Trim()) == decimal.Parse(result[1]))
{
socre += 10;
Console.WriteLine("回答正确");
}
else
{
socre += 0;
Console.WriteLine(string.Format("回答错误,正确答案:{0}", decimal.Parse(result[1])));
}
}
Console.WriteLine(string.Format("你的得分是:{0}", socre));
}

public string[] MetodA(int numberA, int numberB, int operation)
{
string[] result = new string[2];
switch (operation)
{
case 0:
result[0] = string.Format("{0}+{1}= ", numberA, numberB);
result[1] = (numberA + numberB).ToString();
break;
case 1:
result[0] = string.Format("{0}-{1}= ", numberA, numberB);
result[1] = (numberA - numberB).ToString();
break;
case 2:
result[0] = string.Format("{0}*{1}= ", numberA, numberB);
result[1] = (numberA * numberB).ToString();
break;
case 3:
result[0] = string.Format("{0}/{1}= ", numberA, numberB);
result[1] = (decimal.Parse(numberA.ToString()) / decimal.Parse(numberB.ToString())).ToString();
break;
}

return result;
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式