不见棺材不落泪,不到黄河不死心

 

 

 

 

仿照以前做过的例子,将它们综合一下,稍作修改就可以完成。

下面是程序代码截图:(有点乱)

 

 

 

 

 

 

psp耗时分析:

总结:对我而言,有点难,确实也是很有帮助的,相信,今后会做的更好,加油!

思考题:如果用户要求处理的范围是0——100,程序应该如何设计才能很轻松的应对扩展性。

只需将:int x= sjs.Next(0,11);

int y =sjs.Next(0,11);改为:

int x= sjs.Next(0,101);

int y =sjs.Next(0,101);

即可。

代码如下:

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("需要进行哪种就敲出哪种");
            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();

            }
        }
    }

运行结果:

   

posted on 2015-10-06 20:29  情书不朽  阅读(399)  评论(1编辑  收藏  举报