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 though
t 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();
}
}
}
[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();
}
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!?