请帮我调试一下我的计算器程序
本文关键字:一下 我的 计算器 程序 调试 | 更新日期: 2023-09-27 18:06:08
我想做一个计算器。当我代入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;
}
马上,你没有正确分割。
string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X');
如果你输入:
25 * 4 / 10
你应该把分隔符从'X'改为'*'
string[] calCulation = CALCULATION.Text.Split('-', '+', '/', '*');
您将需要进一步更改case语句。或者确保你的输入是正确的