本人初学计算机语言,遇到个题目,自己写的有些问题,请高手们指教!
题目:从键盘上输入两个整数,由用户回答它们的和,差,积,商和取余运算结果,并统计出正确答案的个数。
程序: public class Program
    {
        class test
        {
            public static int add(int a, int b)
            {
                return a + b;
            }
            public static int minus(int a, int b)
            {
                return a - b;
            }
            public static int mul(int a, int b)
            {
                return a * b;
            }
            public static int divide(int a, int b)
            {
                return a / b;
            }
            public static int quyu(int a, int b)
            {
                return a % b;
            }
        }
        static void Main(string[] args)
        {
            int a,b,c,i;
            Console.WriteLine("请输入两个整数:");
            a=Console.Read();
            b=Console.Read();
            Console.WriteLine("请输入这两个整数的和、差、积、商、取余:");
            int[] d;
            for(i=0;i<=4;i++)
            {
                d[i]=Console.Read();
            }
            c=0;
            if(d[0]==test.add(a,b))
                c++;
            else if(d[1]==test.minus(a,b))
                c++;
            else if(d[2]==test.mul(a,b))
                c++;
            else if(d[3]==test.divide(a,b))
                c++;
            else if(d[4]==test.quyu)
                c++;
            Console.WriteLine("正确答案个数为:"+c);
        }
    }

解决方案 »

  1.   

    有兩個沒寫好。
    int[] d = new int[5];else if(d[4]==test.quyu(a,b); 
      

  2.   


    int[] d = new int[5];else if(d[4] == test.quyu(a,b)); 這個才對,上面少寫右括號。
      

  3.   

    把 Main 改成我下面寫的吧~~        static void Main(string[] args)
            {
                int a, b, c, i;
                int[] d = new int[5];
                Console.WriteLine("請輸入兩個整數:");            int.TryParse(Console.ReadLine(), out a);
                int.TryParse(Console.ReadLine(), out b);            Console.WriteLine("請輸入這兩個整數的和、差、積、商、取余:");
                for (i = 0; i <= 4; i++)
                {
                    int.TryParse(Console.ReadLine(), out d[i]);
                }
                c = 0;
                if (d[0] == test.add(a, b))
                    c++;
                if (d[1] == test.minus(a, b))//不能用else if,用了只判斷一次。
                    c++;
                if (d[2] == test.mul(a, b))
                    c++;
                if (d[3] == test.divide(a, b))
                    c++;
                if (d[4] == test.quyu(a, b))
                    c++;
                Console.WriteLine("正確答案個數為:" + c);            Console.Read();
            }
      

  4.   

    Console.WriteLine("正確答案個數為:" + c);
    下面的
    Console.Read();
    可以去掉,那個是我在Debug時用的。
      

  5.   

    你读入的数字似乎不对,这样写a和b的值不是你想要的。
    判断的那些else是不是该去掉。