c#编程 屏幕随机显示两个随机数 随机加减乘除 用户输入计算结果判断结果正误 10
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
int m = r.Next(10);//10以内
int n = r.Next(10);
int j = r.Next(1, 5);//1-4
int result=0;
string type="";
switch (j)
{
case 1:
result = m + n;
type ="+";
break;
case 2:
result = m - n;
type = "-";
break;
case 3:
result = m * n;
type = "×";
break;
case 4:
result = m / n;
type = "÷";
break;
//default:break;
}
Console.WriteLine(m + type + n+"=();请输入结果");
int a = int.Parse(Console.ReadLine());
if (a.Equals(result))
{
Console.WriteLine("结果是:" + result+",您的回答是正确的。");
}
else
{
Console.WriteLine("结果是:" + result + ",您的回答是错误的。");
}
Console.ReadLine();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询