-5
我想製作一個計算器。每當我把像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;
}
添加一些中斷點並調試自己。找到這個問題的答案的最佳方式。 – CharithJ
button16,hey,final2,freak,num vs cal不記分任何可讀性點。這些事情很重要。很多。因爲突然你不能再調試代碼了。 –