Format help for program on Visual Basic in C#
Help! I am trying to make a simple calculator for a C# class and I am
having trouble with the coding side of the problem. It keeps giving me
tons of errors and I am truly not sure why. The code that I have is below.
It keeps telling me that certain names do not exist but I am not sure how
to fix this.
namespace CS4 { public partial class Form1 : Form { public Form1() {
InitializeComponent(); }
int cintEmployeeCount;
decimal cdecTotalNetPay;
const decimal cdecFICA_RATE = 0.06M;
const decimal cdecFEDERAL_RATE = 0.15M;
const decimal cdecSTATE_RATE = 0.05M;
const decimal cdecUNION_DUES = 10.0M;
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label6_Click(object sender, EventArgs e)
{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void btnCalculate_Click(object sender, EventArgs e)
{
int intHoursWorked;
decimal decPayRate;
decimal decGrossPay;
decimal decNetPay;
decimal decAverageNetPay;
try
{
intHoursWorked = int.Parse(txtHoursWorked.Text);
try
{
decPayRate = decimal.Parse (txtPayRate.Text);
decGrossPay = intHoursWorked * decPayRate;
decNetPay = decGrossPay - (decFica + + decState +
cdecUNION_DUES);
cdecTotalNetPay += decNetPay;
cintEmployeeCount += 1;
decAverageNetPay = cdecTotalNetPay / cintEmployeeCount;
lblGrossPay.Text = decGrossPay.ToString("C");
lblFICATax.Text = cdecFICA_RATE.ToString("C");
lblStateTax.Text = cdecSTATE_RATE.ToString("C");
lblFederalTax.Text = cdecFEDERAL_RATE.ToString("C");
lblUnionDues.Text = cdecUNION_DUES.ToString("C");
lblTotalNetPay.Text = cdecTotalNetPay.ToString("C");
lblEmployeeCount.Text = cintEmployeeCount.ToString("N0");
lblAverageNetPay.Text = decAverageNetPay.ToString("C");
}
catch (FormatException err)
{
MessageBox.Show("Pay Rate must be numeric." + err.Message);
"Data Entry Error"; MessageBoxButtons.OK;
MessageBoxIcon.Exclamation;;
txtRate.SelectAll();
txtRate.Focus();
}
}
catch (FormatException err)
{
MessageBox.Show("Hours worked must be numeric." + err.Message,
"Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtHoursWorked.SelectAll();
txtHoursWorked.Focus();
}
catch (Exception err)
{
MessageBox.Show("Unexpected Error: " + err.Message);
}
}
private void btnClearForm_Click(object sender, EventArgs e)
{
txtHoursWorked.Clear();
txtPayRate.Clear();
lblGrossPay.Text ="";
lblFICATax.Text = "";
lblStateTax.Text = "";
lblFederalTax.Text = "";
lblUnionDues.Text = "";
lblNetPay.Text = "";
lblTotalNetPay.Text = "";
lblEmployeeCount.Text = "";
lblAverageNetPay.Text = "";
cdecTotalNetPay = 0;
cintEmployeeCount = 0;
txtHoursWorked.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}//end of class
}//end of namespace
No comments:
Post a Comment