请帮我调试我的计算器程序
我正在尝试制作一个计算器。每当我输入类似 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;
}
I am trying to make a calculator. Whenever I put in something like 25 * 4 / 10 , it divides 25 by 4. Here is the part of the code I think might be the problem:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
马上,你就没有正确分裂。
鉴于您输入:
您应该将拆分从“X”更改为“*”
您还需要更改案例声明。或者确保您的输入正确。
Right off the bat, you are not splitting correctly.
given that you typed:
you should change your split from 'X' to '*'
You will further need to change your case statement. Or make sure your input is correct.