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

同甘苦共患难;

时间:2015-10-18 22:49:48      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:

需求分析:上次的作业、需要添加的代码、多个人的思维。

具体设计思路:通过上次的基础上添加几行代码,实现更多的需求,基本上就这么多。

代码实现:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("------计算器说明书------");
            Console.WriteLine("加减乘除,分别由+-*/代表");
            Console.WriteLine("需要进行哪种就敲出哪种");
            Console.WriteLine("按“v”键结束!");
            do
            {
                Random sjs = new Random();

                int x = sjs.Next(0, 11);
                int y = sjs.Next(0, 11);
                int j = 0;
                int k = 0;
                string a = Console.ReadLine();

 

                if (a == "+")
                {
                    Console.WriteLine("{0}+{1}=", x, y);
                    int b = Convert.ToInt32(Console.ReadLine());
                    if (b == x + y)
                    {
                        Console.WriteLine("算你蒙对了");
                        j++;
                    }

                    else
                    {
                        Console.WriteLine("蠢货,这么简单都不会!");
                        k++;

                    }
                }
                else

                    if (a == "-")
                    {
                      

                        Console.WriteLine("{0}-{1}=", x, y);

                        int b = Convert.ToInt32(Console.ReadLine());

                        if (b == x - y )
                        {
                            Console.WriteLine("算你蒙对了");
                            j++;
                        }
                      

 

                        else
                        {

                            Console.WriteLine("蠢货,这么简单都不会!");

                            k++;

                        }

                    }

                    else

                        if (a == "*")
                        {

                            Console.WriteLine("{0}*{1}=", x, y);

                            int b = Convert.ToInt32(Console.ReadLine());

                            if (b == x * y)
                            {
                                Console.WriteLine("算你蒙对了");
                                j++;
                            }
                            else
                            {

                                Console.WriteLine("蠢货,这么简单都不会!");

                                k++;

                            }

                        }

                        else

                            if (a == "/")
                            {

                                Console.WriteLine("{0}/{1}=", x, y);

                                int b = Convert.ToInt32(Console.ReadLine());

                                if (b == x / y)
                                {
                                    Console.WriteLine("算你蒙对了");
                                    j++;
                                }

                                else
                                {

                                    Console.WriteLine("蠢货,这么简单都不会!");

                                    k++;
                                }
                            }
                Console.WriteLine("你一共做了{0}道,答对{1}题,答错{2}题!", j + k, j, k);
            }

            while (Console.ReadLine() != "v");

            Console.ReadLine();

        }
    }

}

 

 

 

测试结果:

技术分享

 

psp耗时:

技术分享

 

 

总结:本次作业主要是让我们结对编程,我认为这种方法更能发挥多个人的特长,很不错,非常赞同这种学习方法。

 

同甘苦共患难;

标签:

原文地址:http://www.cnblogs.com/zsj233/p/4890402.html

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