Question: private void btnCalculate_Click(object sender, EventArgs e) { //get the textbox income decimal income; decimal.TryParse(txtTax.Text, out income); //declare a variable for the tax decimal tax =

private void btnCalculate_Click(object sender, EventArgs e) {

//get the textbox income decimal income; decimal.TryParse(txtTax.Text, out income); //declare a variable for the tax decimal tax = 0m; //tax value presented by calling the CalculateTax method. tax = CalculateTax(income); //display tax txtIncome.Text = tax.ToString(); } //private method named CalculateTax that receives the income amount and returns the tax amount. private decimal CalculateTax(decimal income) { //declare a variable for the tax decimal tax = 0m; //calculate the tax owed based on income if (income 9875 && income 40126 && income 85526 && income 163301 && income 207351 && income 518400) tax = 156235m + (int)((income - 518400) * .37m); else

MessageBox.Show("Invalid input format. Please check all entries");

//return the calculated tax amount

return tax;

} //event handler that clears the Income Tax Owed text box if the user changes the value in the Taxable Income text box. private void txtTax_TextChanged(object sender, EventArgs e) { txtIncome.Text = ""; }

private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }

How can I make the message box work if the user inputs the wrong entry. I cant get it to work.

Like this

 private void btnCalculate_Click(object sender, EventArgs e) { //get the textbox income

File Edit View Git Project Build Debug Test Analyze Tools Extensions Window Help Search (Ctrl+Q) income TaxCalculator Debug Any CPU Continue Income TaxCald Form 1 Income TaxCalculator.cs (Design) income TaxCalculator.Income TaxCalculator ncome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!