2011-08-18 13 views
-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; 
    } 
+3

添加一些中斷點並調試自己。找到這個問題的答案的最佳方式。 – CharithJ

+4

button16,hey,final2,freak,num vs cal不記分任何可讀性點。這些事情很重要。很多。因爲突然你不能再調試代碼了。 –

回答

2

馬上蝙蝠,你是不是正確的分裂。

string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X'); 

給您鍵入:

25 * 4/10 

你應該將拆分從 'X' 更改爲 '*'

string[] calCulation = CALCULATION.Text.Split('-', '+', '/', '*'); 

您將進一步需要改變你的case語句。或者確保你的輸入是正確的。

+0

nooo其實我輸入25X4/10哎呀我搞砸了 –