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

第二次作业

时间:2015-10-05 23:19:48      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

技术分享技术分享技术分享

namespace boke
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            Random rd = new Random();
            a = rd.Next(0, 11);
            b = rd.Next(0, 11);
            Console.WriteLine("第一个数:{0}",a);
            Console .WriteLine ("第二个数:{0}",b);
            Console.WriteLine("请输入运算符号:‘+‘,‘-‘,‘*‘,‘/‘");
            string c = Console.ReadLine();
            if (c == "+")
            {
                int d;
                d = a + b;
                Console.WriteLine ("结果是:");
                Console.ReadLine();
                Console.WriteLine("正确答案是:{0}", d); 
            }
            else if (c == "-")
            {
                int d;
                d = a - b;
                Console.WriteLine("结果是:");
                Console.ReadLine();
                Console.WriteLine("正确答案是:{0}", d); 
            }
            else if (c == "*")
            {
                int d;
                d = a * b;
                Console.WriteLine("结果是:");
                Console.ReadLine();
                Console.WriteLine("正确答案是:{0}", d); 
            }
            else if (c == "/")
            {
                int d;
                d = a / b;
                Console.WriteLine("结果是:");
                Console.ReadLine();
                Console.WriteLine("正确答案是:{0}", d); 
            }
            else
            {
                Console.WriteLine("您输入的运算符无效");
            }
            Console .ReadLine ();
        }
    }
}

1、看清题目的要求,编写简单计算器的代码。

2、选择相应的程序进行编写。

3、要想产生随机数,首先用Random进行定义。

4、然后对四个运算符号进行描述。

5、最后把正确结果写出,进行运行测试。

因为能力有限,编写的代码不太符合要求,望老师多多谅解。

第二次作业

标签:

原文地址:http://www.cnblogs.com/githubgxp/p/4856378.html

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