I have my program working and compiling correctly, but I am having an issue getting the maximum and default installations set. I would really appreciate some pointers. I'm new to C#, so any help is greatly appreciated!A few guidelines: 'H' can have a maximum of 5 installations. The default is 1.'E' has a default of 10 installations included. For each installation above 10, the additional price is added. Both 'H' and 'E' have a default of additional programs of 0. Number must not be negative.Here is my code thus far: Collapse | Copy Code private void btnCalculate_Click(object sender, EventArgs e)
{
const decimal U_CUST = 999;
const decimal E_CUST = 249;
const decimal ADD_E_CUST = 99;
const decimal H_CUST = 99;
const decimal ADD_H_CUST = 49;
char CustType;
int AdditionalPrograms = 0;
int Installations = 10;
decimal Bill = 0;
if (txtCustType.Text.Length != 1)
{
MessageBox.Show("Customer type is required.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCustType.Focus();
return;
}
CustType = char.Parse(txtCustType.Text);
CustType = char.ToUpper(CustType);
txtCustType.Text = CustType.ToString();
if (CustType != 'U' && CustType != 'H' && CustType != 'E')
{
MessageBox.Show("Invalid customer type - must be H, E or U.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCustType.Focus();
return;
}
if (CustType == 'U')
{
Bill = U_CUST;
}
else
{
if (txtAddPrograms.Text != "") {
bool isValid = int.TryParse(txtAddPrograms.Text, out AdditionalPrograms);
if (!isValid || AdditionalPrograms < 0)
{
MessageBox.Show("Invalid number of additional programs - can't be negative.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAddPrograms.Focus();
return;
}
}
if (CustType == 'H')
{
Bill = H_CUST + ADD_H_CUST * AdditionalPrograms;
}
else {
if (txtInstallations.Text != "") {
bool isValid = int.TryParse(txtInstallations.Text, out Installations);
if (!isValid || Installations < 1)
{
MessageBox.Show("Invalid number of installations - must be positive.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtInstallations.Focus();
return;
}
}
Bill = E_CUST + ADD_E_CUST * AdditionalPrograms;
if (Installations > 10) Bill *= 1 + (Installations - 10) * 0.1m;
}
}
lblBill.Text = Bill.ToString("C");
if (CustType == 'E' && Installations > 40)
{
MessageBox.Show("Note that the unlimited plan would be more economic.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}