天天看點

第三次作業:0~10的随機四則運算

    雖然放假前有讓同宿舍的女生把軟體給我弄到U盤裡,但是結果回家安裝不上,是以就隻是在記事本裡打了代碼。結果能不能運作其實我并不知道,隻是把一些代碼發上來。

    下面就是我的代碼

 namespace   add

   {

       class   Program

       {

          static    void  Main(string[] args)

           {

               int    right=0;

               int    wrong=0;

               do

                {

                    Random  sj=new Random();

                    int  x=sj.Next(0,11);

                    int  y=sj.Next(1,3);

                    Console.WriteLine("請選擇一項進行運算+,-,*,/;或者按Enter後輸入P結束程序");

                    string i=Convert.ToString(Console.ReadLine());

                    if(i == "+")

                    {

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

                        int z=Conver.ToInt32(Console.ReadLine());

                        if(z == x + y)

                        {

                        right++;

                        }

                        else

                           Console.WriteLine("抱歉,回答錯誤!");

                           wrong++;

                     }

                     else

                      if(i == "-")

                      {

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

                          int z=Conver.ToInt32(Console.ReadLine());

                          int(z ==x - y)

                          {

                             right++;

                           }

                           else

                             Console.WriteLine("抱歉,回答錯誤!");

                             wrong++;

                         if(i == "*")

                         {

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

                            int z=Conver.ToInt32(Console.ReadLine());

                            if(z == x * y)

                            {

                               right++;

                            }

                            else

                               Console.WriteLine("抱歉,回答錯誤!");

                               wrong++;

                             }

                           if(i == "/")

                           {

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

                               int z = Conver.ToInt32(Console.ReadLine());

                               if(z == x/y)

                                {

                                   right++;

                                 }

                                 else

                                 {

                                   Console.WriteLine("抱歉,回答錯誤!");

                                   wrong++;

                                   }

                                }

                          }

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

                           Console.WriteLine("您答了{0}題,正确:{1},錯誤:{2}",right+wrong,right,wrong);

                           Console.ReadLine();

                    }

               }

       }

     這個就是我的代碼了,我明天回學校會先運作的,如果不成功,我會再改進。