我正在尝试制作一个计算器。每当我输入像25 * 4/10这样的东西时,它将25除以4.这是我认为可能是问题的代码的一部分:
private void button16_Click(object sender, RoutedEventArgs e)
{
string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X');
int numOfItems = calCulation.Length;
int count = 1;
char[] Arius = new char[Hey.Length];
foreach(char words in Hey)
{
int outlie = 0;
Arius[outlie] = words;
outlie++;
}
decimal final = 0M;
decimal[] calCulate = new decimal[numOfItems];
int countfreak = 0;
foreach (string word in calCulation)
{
calCulate[countfreak] = Convert.ToDecimal(word);
countfreak++;
}
int counting = 1;
int countinghey = 0;
decimal final2 = calCulate[0];
while(count < numOfItems){
switch(Arius[countinghey])
{
case 'X':
/*
final2 += final * calCulate[counting -1];
final2 = final2 * calCulate[counting];
*/
final2 = final2 * calCulate[counting];
break;
case '-':
final2 = final2 - calCulate[counting];
break;
case '+':
final2 = final2 + calCulate[counting];
break;
case '/':
final2 = final2 / calCulate[counting];
break;
}
counting++;
countinghey++;
count++;
}
CALCULATION.Text = Convert.ToString(final2);
}
public bool Parshing(string value, string typee)
{
int hixty = value.Length;
string six = value.Substring(hixty - 1, value.Length - hixty + 1);
int lam;
bool result = Int32.TryParse(six, out lam);
if (result == true||six == "")
{
CALCULATION.Text += typee;
Hey += typee;
}
else
{
}
return result;
}
答案 0 :(得分:2)
蝙蝠,你没有正确分裂。
string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X');
鉴于你输入了:
25 * 4 / 10
您应该将分割从“X”更改为“*”
string[] calCulation = CALCULATION.Text.Split('-', '+', '/', '*');
您还需要更改案例陈述。或者确保输入正确。