using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*namespace Point
{
    class Program
    {
        static void Main()
        {
            float f = 1.2550f;
            Console.WriteLine(Math.Round(f, 2));
            string re;
            re = f.ToString("#0.00");  //保留小数点后两位
            Console.WriteLine(re);
            re = f.ToString("f2");
            Console.WriteLine(re);
            int a = 9;
            int b = 61;
            float d = float.Parse(Console.ReadLine());
            Console.WriteLine(float.Parse(((float)a/b).ToString("f2"))==d);      //类型之间的转换
        }
    }
}*/
namespace Question
{
    class Program
    {
        static void Main()
        {
            int Grade_Count=0;     //计分
            Random R = new Random();
            int a;     //用来决定加、减、乘、除中的一种运算
            for (int i = 0; i < 10; i++)   //出10道题
            {
                int First_Num;        //第一个元素
                int Second_Num;      //第二个元素
                First_Num = R.Next(100);
                label: Second_Num = R.Next(100);
                int Res;     //结果
                string s;
                a = R.Next(4) + 1;
                switch (a)
                {
                    case 1:         //加法运算
                        Console.WriteLine(First_Num + "+" + Second_Num + "=");
                        s = Console.ReadLine();
                        Res = int.Parse(s);
                        if (First_Num + Second_Num == Res)
                        {
                            Console.WriteLine("回答正确");
                            Grade_Count++;
                        }
                        else
                        {
                            Console.WriteLine("回答错误");
                            Console.WriteLine("正确答案为:" + (First_Num + Second_Num));
                        }
                        break;
                    case 2:        //减法
                        Console.WriteLine(First_Num +"-"+ Second_Num +"=");
                        s = Console.ReadLine();
                        Res = int.Parse(s);
                        if (First_Num - Second_Num == Res)
                        {
                            Console.WriteLine("回答正确");
                            Grade_Count++;
                        }
                        else
                        {
                            Console.WriteLine("回答错误");
                            Console.WriteLine("正确答案为:" + (First_Num - Second_Num));
                        }
                        break;
                    case 3:           //乘法
                        Console.WriteLine(First_Num + "*" + Second_Num + "=");
                        s = Console.ReadLine();
                        Res = int.Parse(s);
                        if (First_Num * Second_Num == Res)
                        {
                            Console.WriteLine("回答正确");
                            Grade_Count++;
                        }
                        else
                        {
                            Console.WriteLine("回答错误");
                            Console.WriteLine("正确答案为:" + (First_Num * Second_Num));
                        }
                        break;
                    case 4:          //除法
                        Console.WriteLine(First_Num +"/" +Second_Num +"=");
                        s = Console.ReadLine();
                       // Res = int.Parse(s);
                        float f = float.Parse(s);
                        if (Second_Num == 0)
                        {
                            goto label;
                        }
                        else
                        {
                            if (float.Parse(((float)First_Num / Second_Num).ToString("f2")) == f)
                            {
                                Console.WriteLine("回答正确");
                                Grade_Count++;
                            }
                            else
                            {
                                Console.WriteLine("回答错误");
                                Console.WriteLine("正确答案为:" + float.Parse(((float)First_Num / Second_Num).ToString("f2")));
                            }
                        }
                        break;
                }
            }
            Console.WriteLine("你的总得分为:"+ Grade_Count);
        }
    }
}


本文转载:CSDN博客