同甘苦共患难;

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

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

代码实现:

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耗时:

 

 

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

 

posted on 2015-10-18 21:46  情书不朽  阅读(826)  评论(1编辑  收藏  举报