码迷,mamicode.com
首页 > 其他好文 > 详细

实现四则

时间:2015-10-01 12:49:09      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你想做的运算+,-,*,/ ");
string m = Console.ReadLine() ;
switch (m)
{
case "+":
Shu.Wo();
break;
case "-":
Shu.Sub();
break;
case "*":
Shu.Sheng();
break;
case "/":
Shu.Chu();
break;

}
Console.ReadLine();
}
}

//定义委托
public delegate double Num(double x,double y);
public class Math
{
public static double Add(double x, double y)
{ return x + y; }
public static double Sub(double x, double y)
{ return x - y; }
public static double Sheng(double x, double y)
{ return x * y; }
public static double Chu(double x, double y)
{ return x / y; }
}
public class Shu


public static int i = 0;
public static int right = 0;
public static void Wo()
{


double sum, n;
Random r = new Random();
double x = r.Next(0,10);
double y= r.Next(0, 10);
sum = x + y;
Console.WriteLine("{0}+{1}=",x,y);
Console.WriteLine("请输入你的结果:");
n=double.Parse( Console.ReadLine());
Num nu = new Num(Math.Add);
Console.WriteLine("正确结果是:");
Console.WriteLine("{0}+{1}={2}",x,y,nu(x,y));
if (sum == n)
{
Console.WriteLine("你的结果正确!");
i++;
right++;
Wo();

}
else if (n == 99)
{
Jieshu();

}
else
{
Console.WriteLine("你的结果不正确");
i++;
Wo();
}
}
public static void Jieshu()
{

Console.WriteLine("你好,你已退出计算!你公做{0}道题,答对{1}",i,right);

}
public static void Sub()
{


double sum, n;
Random r = new Random();
double x = r.Next(0, 10);
double y = r.Next(0, 10);

sum = x - y;
Console.WriteLine("{0}-{1}=", x, y);
Console.WriteLine("请输入你的结果:");
n = double.Parse(Console.ReadLine());
Num nu = new Num(Math.Sub);
Console.WriteLine("正确结果是:");
Console.WriteLine("{0}-{1}={2}", x, y, nu(x, y));
if (sum == n)
{
Console.WriteLine("你的结果正确!");
i++;
right++;
Wo();


}
else if (n == 99)
{
Jieshu();

}
else
{
Console.WriteLine("你的结果不正确");
i++;
Sub();
}
}
public static void Sheng()
{


double sum, n;
Random r = new Random();
double x = r.Next(0, 10);
double y = r.Next(0, 10);
sum = x *y;
Console.WriteLine("{0}*{1}=", x, y);
Console.WriteLine("请输入你的结果:");
n = double.Parse(Console.ReadLine());
Num nu = new Num(Math.Sheng);
Console.WriteLine("正确结果是:");
Console.WriteLine("{0}*{1}={2}", x, y, nu(x, y));
if (sum == n)
{
Console.WriteLine("你的结果正确!");
i++;
right++;
Wo();


}
else if (n == 99)
{
Jieshu();

}
else
{
Console.WriteLine("你的结果不正确");
i++;
Sheng();
}
}
public static void Chu()
{


double sum, n;
Random r = new Random();
double x = r.Next(0, 10);
double y = r.Next(0, 10);
sum = x / y;
Console.WriteLine("{0}/{1}=", x, y);
Console.WriteLine("请输入你的结果:");
n = double.Parse(Console.ReadLine());
Num nu = new Num(Math.Chu);
Console.WriteLine("正确结果是:");
Console.WriteLine("{0}/{1}={2}", x, y, nu(x, y));
if (sum == n)
{
Console.WriteLine("你的结果正确!");
i++;
right++;
Wo();


}
else if (n == 99)
{
Jieshu();

}
else
{
Console.WriteLine("你的结果不正确");
i++;
Chu();
}
}

}

}

 

 

 

 

 

实现四则

标签:

原文地址:http://www.cnblogs.com/lydz/p/4850862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!