函数的完成

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tmd
{
    class Program
    {
       private static int sun;
        static void Main(string[] args)
        {
            Console.Write("请输入你要进行的运算(+):");
            string f = Console.ReadLine();
            Console.Write("请输入第一个数:");
            int a = int.Parse(Console.ReadLine());
            Console.Write("请输入第二个数:");
            int b = int.Parse(Console.ReadLine());
            Console.Write("请输入答案:");
            int y = int.Parse(Console.ReadLine());
            calcula(f,a,b);
            if (y == sun)
            {
                Console.WriteLine("恭喜你答对了!");
            }
            else
            {
                Console.WriteLine("很遗憾你答错了!");
                Console.WriteLine(sun);
            }

            Console.Read();
            
            
        }
        private static int calcula(string operato, int a, int b)
        {
           
            switch (operato)
            {
                case "+":
                    sun=a+b;
                    break;
                case "-":
                    sun = a - b;
                    break;
                case "*":
                    sun = a * b;
                    break;
                case "/":
                    sun = a / b;
                    break;

            }
            return sun;
 
        }
    }
}

总结:

用控制台来写的,不知道这样写行不行!

谢谢老师@沉默的代码

原文地址:https://www.cnblogs.com/lizanqirxx/p/4961822.html