The application I am creating is a form that will take a salary that is typed into a text box and calculates the annual amount of income tax. My problem is that I cannot make calculate_Master method to work, so right now I just have the calculate_Single executing when the calculate button is clicked. I would like to make it so that the calculate_Master will call the appropriate method depending on what value the person chooses in the dropdown box. (Single, Married Filing Jointly, or Head of Household)
In this example, the resulting error is:
"Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
Side note: I am in the process of trying to teach myself using online materials and admittedly, I lack some basics that I am trying to catch up on. That being said, I am running up against two issues that I would like help on. If, while you are reviewing this code, notice anything I need to change for conventional practices or any reason, I would appreciate any such advice.
In this example, the resulting error is:
"Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
Side note: I am in the process of trying to teach myself using online materials and admittedly, I lack some basics that I am trying to catch up on. That being said, I am running up against two issues that I would like help on. If, while you are reviewing this code, notice anything I need to change for conventional practices or any reason, I would appreciate any such advice.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TaxCalculator
{
public partial class Form1 : Form
{
string salarynocomma;
string salarycomma;
int salaryint;
int singleA = 8700;
int singleB = 35350;
int singleC = 85650;
int singleD = 178650;
int singleE = 388350;
int jointA = 17400;
int jointB = 70700;
int jointC = 142700;
int jointD = 217450;
int jointE = 388350;
int headA = 12400;
int headB = 47350;
int headC = 122300;
int headD = 198050;
int headE = 388350;
double bracketArate = .10;
double bracketBrate = .15;
double bracketCrate = .25;
double bracketDrate = .28;
double bracketErate = .33;
double bracketFrate = .35;
double taxresult;
public Form1()
{
InitializeComponent();
}
private void testSalaryInput_Click(object sender, EventArgs e)
{
}
private void calculate_Master(object sender, EventArgs e)
{
MessageBox.Show("You entered " + salarycomma + ".");
if (filingStatusDropdown.Text == "Single")
{
calculate_Single;
taxResultLabel.Text = taxresult.ToString();
}
else if(filingStatusDropdown.Text == "Married Filing Jointly")
{
calculate_Joint;
taxResultLabel.Text = taxresult.ToString();
}
else if (filingStatusDropdown.Text == "Head of Household")
{
calculate_Head;
taxResultLabel.Text = taxresult.ToString();
}
else
{
MessageBox.Show("Please select a valid filing status.");
}
taxResultLabel.Text = taxresult.ToString();
}
private void calculate_Single(object taxresult, EventArgs e)
{
//Remove comma from salary input and convert it to int
salarycomma = salaryTextBox.Text;
salarynocomma = salarycomma.Replace(",", "");
salaryint = int.Parse(salarynocomma);
//Calculate using Single Filing Status tax brackets
if (salaryint < 0){MessageBox.Show("What is wrong with you? Put in a number above 0.");}
else if (salaryint <= singleA) {taxresult = salaryint * bracketArate;}
else if (salaryint <= singleB) {taxresult = salaryint * bracketBrate;}
else if (salaryint <= singleC) {taxresult = salaryint * bracketCrate;}
else if (salaryint <= singleD) {taxresult = salaryint * bracketDrate;}
else if (salaryint <= singleE) {taxresult = salaryint * bracketErate;}
else if (salaryint > singleE) {taxresult = salaryint * bracketFrate;}
else
{
MessageBox.Show("I think something is wrong with what you put in.");
}
taxResultLabel.Text = taxresult.ToString();
}
private void calculate_Joint(object sender, EventArgs e)
{
//Remove comma from salary input and convert it to int
salarycomma = salaryTextBox.Text;
salarynocomma = salarycomma.Replace(",", "");
salaryint = int.Parse(salarynocomma);
//Calculate using Joint Filing Status tax brackets
if (salaryint < 0) { MessageBox.Show("What is wrong with you? Put in a number above 0."); }
else if (salaryint <= jointA) { taxresult = salaryint * bracketArate; }
else if (salaryint <= jointB) { taxresult = salaryint * bracketBrate; }
else if (salaryint <= jointC) { taxresult = salaryint * bracketCrate; }
else if (salaryint <= jointD) { taxresult = salaryint * bracketDrate; }
else if (salaryint <= jointE) { taxresult = salaryint * bracketErate; }
else if (salaryint > jointE) { taxresult = salaryint * bracketFrate; }
else
{
MessageBox.Show("I think something is wrong with what you put in.");
}
taxResultLabel.Text = taxresult.ToString();
}
private void calculate_Head(object sender, EventArgs e)
{
//Remove comma from salary input and convert it to int
salarycomma = salaryTextBox.Text;
salarynocomma = salarycomma.Replace(",", "");
salaryint = int.Parse(salarynocomma);
//Calculate using Head of Household Filing Status tax brackets
if (salaryint < 0) { MessageBox.Show("What is wrong with you? Put in a number above 0."); }
else if (salaryint <= headA) { taxresult = salaryint * bracketArate; }
else if (salaryint <= headB) { taxresult = salaryint * bracketBrate; }
else if (salaryint <= headC) { taxresult = salaryint * bracketCrate; }
else if (salaryint <= headD) { taxresult = salaryint * bracketDrate; }
else if (salaryint <= headE) { taxresult = salaryint * bracketErate; }
else if (salaryint > headE) { taxresult = salaryint * bracketFrate; }
else
{
MessageBox.Show("I think something is wrong with what you put in.");
}
taxResultLabel.Text = taxresult.ToString();
}
private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}
}
}