Reputation: 11
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) {
}
}
}
I am not getting any text in my read-only outputTxt textbox. Any help is appreciated. I need the outputTxt to display after each click event of the Calculate button. I have used the HoldInteger to hold intermediary calculations for the outputinteger which should be the final output for each selection of a radio button.My form
Upvotes: 0
Views: 62
Reputation: 3584
Everything is fine except ; after if(condition);
remove all ; just after the conditional statements. and write like if(condition){}
then you are good to go.
Upvotes: 0
Reputation: 24901
You need to remove ;
from the end of each if
statement.
Change
if (depositBtn.Checked == true) ;
to
if (depositBtn.Checked == true)
Do it in all places where you used ;
after if
statement.
This is because if you are using ;
after if
statement you are effectively adding an empty script block. These codes are basically identical:
// 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();
}
Upvotes: 7