2015-10-19 77 views
0
public partial class Form1: Form { 
    // Define a few variables 
    int InputInteger; 
    int HoldInteger; 
    int OutputInteger; 

    public Form1() { 
     InitializeComponent(); 
    } 

    private void exitBtn_Click(object sender, EventArgs e) { 
     //Used to close the form when exit is clicked 
     this.Close(); 
    } 

    private void clearBtn_Click(object sender, EventArgs e) { 
     //this will deselect all of the radio buttons, along with clearing the 
     // textboxes with input and output information. 
     depositBtn.Checked = false; 
     checksBtn.Checked = false; 
     serviceBtn.Checked = false; 
     inputTxt.Clear(); 
     outputTxt.Clear(); 
    } 

    private void calculateBtn_Click(object sender, EventArgs e) { 

     // Calculate button actions 
     try { 
      InputInteger = Convert.ToInt32(inputTxt.Text); 
      // For each radio button checked gives an action to the calculate button 
      if (depositBtn.Checked == true); { 
       OutputInteger = (InputInteger + HoldInteger); 
       outputTxt.Text = OutputInteger.ToString(); 

      } else if (checksBtn.Checked == true); { 
       if (InputInteger > OutputInteger); { 
        OutputInteger = (HoldInteger - 10); 
        outputTxt.Text = OutputInteger.ToString(); 
        MessageBox.Show("Insufficient Funds"); 
        if (HoldInteger < 0); { 
         MessageBox.Show("Negative account balance"); 
        } 
       } else if (InputInteger <= HoldInteger); { 
        OutputInteger = (InputInteger - HoldInteger); 
        outputTxt.Text = OutputInteger.ToString(); 

       } 
      } else if (serviceBtn.Checked); { 
       if (InputInteger > OutputInteger); { 
        OutputInteger = (HoldInteger - 10); 
        outputTxt.Text = OutputInteger.ToString(); 
        MessageBox.Show("Insufficient Funds"); 
        if (HoldInteger < 0); { 
         MessageBox.Show("Negative account balance"); 
        } 
       } else if (InputInteger <= HoldInteger); { 
        OutputInteger = (InputInteger - HoldInteger); 
        outputTxt.Text = OutputInteger.ToString(); 

       } 
      } 
     } catch { 

     } 

    } 

    private void outputTxt_TextChanged(object sender, EventArgs e) { 

    } 
} 
} 

我没有在我的只读outputTxt文本框中获取任何文本。任何帮助表示赞赏。我需要在计算按钮的每次单击事件后显示outputTxt。我已经使用HoldInteger来保存输出整数的中间计算,它应该是每次选择单选按钮的最终输出。 My formC#程序不显示输出值

+0

神圣的废话我觉得自己像一个白痴,不应该试图写一个分心的程序。感谢一堆dotnetom! –

回答

7

您需要从每个if声明的末尾删除;

变化

if (depositBtn.Checked == true) ; 

if (depositBtn.Checked == true) 

做它在你之后if语句中使用;所有地方。

这是因为如果在if语句之后使用;,则表明您正在有效地添加一个空的脚本块。这些代码基本相同:

// this code block 
if (depositBtn.Checked == true); 
{ 
    OutputInteger = (InputInteger + HoldInteger); 
    outputTxt.Text = OutputInteger.ToString(); 
} 

//is identical to 
if (depositBtn.Checked == true) 
{ 
} 
{ 
    OutputInteger = (InputInteger + HoldInteger); 
    outputTxt.Text = OutputInteger.ToString(); 
} 
0

一切都很好,除了;之后if(condition); 删除全部;就在条件语句之后。并写如if(condition){} 然后你很好去。