问题描述
Hej在这里,
我只是C#中的新手,对于火车,我想创建一个Console-Calculator.我只有一个简单的可以1 + 1和1-1的游戏,依此类推,但是现在我想要一个更大的游戏,它可以观察到嗯,它在英语中被称为点到短跑规则"吗?我不知道抱歉,不过是一个例子->
我简单的计算器就是这样->
2 + 2 * 2 = 8
但我希望他像->
一样工作
2 + 2 * 2 = 6
希望你们知道我的意思;)
因此,尽管 t是将计算分为数字和单数形式的最佳方法.
这已经可以用了,但是我不知道该怎么做才能得到计算结果:X
希望你们能帮助我.我已经准备好的继承人代码:
Hej there,
Iam just new in C# and for train I want to create a Console-Calculator. I just got a simple one that can 1+1 and 1-1 and so on but now i want a bigger one that observes the hmm is it called Dot to Dash rule in English? I don´t know sorry but an example ->
My simple Calculator is working like this ->
2+2*2 = 8
but i want him to work like ->
2+2*2 = 6
Hope you guys know what i mean ;)
So i thought it would be the best way to split up the calculation in numbers and sings.
This works allready but i don´t know what I should do right now to get the result of a calculation :X
Hope you guys can help me. Heres my Code that i wrote allready:
{
public static void Main()
{
int count = 0;
Console.WriteLine("Insert your Calculation");
string calculation = Console.ReadLine();
string[] splitnumbers = calculation.Split(new Char[] { ''+'', ''-'', ''*'', ''/'' });
string[] splitsigns = calculation.Split(new Char[] { ''0'', ''1'', ''2'', ''3'', ''4'', ''5'', ''6'', ''7'', ''8'', ''9'' });
foreach (string s in splitnumbers)
{
count++;
if (s.Trim() != "")
Console.WriteLine(s);
Console.WriteLine(splitsigns[count]);
Console.WriteLine("For exit press Enter");
Console.Read();
}
}
}
[已将OP评论从答案中移出]
好吧,我现在只想走另一条路...
[Moved OP comment from answer]
Okay now i just want to go another way...
for (int i = 0; i < splitnumbers.Length - 1; i++)
{
int firstNumber = int.Parse(splitnumbers[i].ToString());
int secondNumber = int.Parse(splitnumbers[i + 1].ToString());
string operatorString = splitsigns[i + 1].ToString();
}
但是现在呢?以为我必须得到这个结果或水木清华.并计算出下一步,例如5 + 6 * 7!?
But what now? Thought i have to get the result of this or smth. and denn calculate the next step in for example 5+6*7!?
推荐答案
这篇关于具有SplitStrings的C#计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!