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

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

代码实现:

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

同甘苦共患难;

 

 

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

 

相关文章:

  • 2021-11-13
  • 2021-08-26
  • 2021-08-09
  • 2021-12-16
  • 2021-12-22
  • 2022-01-14
  • 2021-12-12
  • 2021-12-15
猜你喜欢
  • 2021-11-22
  • 2021-11-29
  • 2021-08-26
  • 2021-12-07
  • 2021-10-08
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案