• C#简易计算器


    简单计算器

    实现一个简单控制台应用程序的计算器

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace DesignModel
    {
       public class Program
        {
           public static void Main(string[] args)
            {
                #region  计算器
    
                try
                {
                    Console.WriteLine("请输入数字A:");
                    string NumberA = Console.ReadLine();
                    Console.WriteLine("请选择运算(+ - * /)");
                    string strOption = Console.ReadLine();
                      Console.WriteLine("请输入数字B:");
                    string NumberB = Console.ReadLine();
                    string Result = "";
                    switch (strOption)
                    {
                        case "+":
                            Result =Convert.ToString( Convert.ToInt32( NumberA )+ Convert.ToInt32( NumberB));
                            break;
                        case "-":
                            Result = Convert.ToString(Convert.ToInt32(NumberA) - Convert.ToInt32(NumberB));
                            break;
                        case "*":
                             Result = Convert.ToString(Convert.ToInt32(NumberA)* Convert.ToInt32(NumberB));
                            break;
                        case "/":
                            //三目运算
                          NumberB=  NumberB != "0" ? Result = Convert.ToString(Convert.ToInt32(NumberA) / Convert.ToInt32(NumberB)) : Result = "除数不能是0";
    
                            break;
    
                    }
                    Console.WriteLine("结果是:"+Result);
                    Console.ReadLine();
    
                }
                catch (Exception ex)
                {
    
                    Console.WriteLine(ex);
                }
                #endregion
    
            }
        }
    }
    
  • 相关阅读:
    《代码大全2》阅读笔记02
    《代码大全2》阅读笔记01
    第二阶段冲刺第六天
    学习进度5
    构建之法阅读笔记03
    地铁进度记录
    学习进度4
    个人数组
    学习进度3
    构建之法阅读笔记02
  • 原文地址:https://www.cnblogs.com/zaohuojian/p/11483636.html
Copyright © 2020-2023  润新知