C#简单的控制台计算器
来源:百度知道 编辑:UC知道 时间:2024/05/23 18:46:30
我又不是让你算我输入的 是一个例子 就是可以用户随便输入无限的数和操作然后可以计算的
8*5-51/61呢 71/51-6+541/5呢...
我以前做过一个窗体上的,转一下给你吧
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个表达式:");
String s = Console.ReadLine();
compute comp = new compute();
Console.WriteLine(comp.Answer(s));
Console.ReadKey();
}
}
class compute
{
public String Answer(String expression)
{
int i, length = expression.Length, k = 0;
String temp;
String[] divide = new String[20];
double result = 0;
double left = 0, right = 0;
bool IsPriority = false;
String operation;
for (i = 0; i < length; i++)
{
temp = expression.Substring(i, 1);
if (!temp.Equals("+") && !temp.Equals("-") && !temp.Equals("*") && !temp.Equals("/"))
{