私はプログラミングが本当に新しいです。 C#は私が取った最初のクラスで、私はこのプロジェクトに固執しています。ワークショップラジオボタンと場所ラジオボタンを選択した後、ワークショップの費用を計算するプログラムを作成しなければなりませんでした。私はそれが1つの事を除いて仮定されているようにすべての作業をしています。ラジオボタンが選択されていない場合、プログラムの計算を停止するにはどうすればよいですか?
ワークショップを選択したが、場所を選択していないとします。私はMessageBox
が「場所を選択する」と表示される場所に持っていますが、このような場合にプログラムが計算を止めるにはどうしたらいいですか?今のところ、それはちょうど計算し、位置量0を与えるでしょう。私は計算しないためにそれが必要です。
public partial class frmWorkshopSelector : Form
{
public frmWorkshopSelector()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close(); //When clicking the exit button, the program will close
}
private void btncalc_Click(object sender, EventArgs e)
{
int wsregistration = 0;
int lcost = 0;
const decimal DAYS = 3;
//For the following if statements, depending on what workshop and location is selected,
//their correstponding registration and lodging fees will be displayed
{
if (rbtHandlingStress.Checked == true)
{
wsregistration = 1000;
}
else if (rbtSupervisionSkills.Checked == true)
{
wsregistration = 1500;
}
else if (rbtTimeManagement.Checked == true)
{
wsregistration = 800;
}
else
MessageBox.Show("Please Select a Workshop");
lblTotalCost.Text = "";
lblLodgingCost.Text = "";
lblRegistrationCost.Text = "";
}
{
if (rbtAustin.Checked == true)
{
lcost = 150;
}
else if (rbtChicago.Checked == true)
{
lcost = 225;
}
else if (rbtDallas.Checked == true)
{
lcost = 175;
}
else
{
MessageBox.Show("Please Select a Location");
lblRegistrationCost.Text = " ";
lblTotalCost.Text = " ";
lblLodgingCost.Text = " ";
}
}
lblRegistrationCost.Text = wsregistration.ToString("C");
lblLodgingCost.Text = lcost.ToString("C");
lblTotalCost.Text = (wsregistration + (lcost * DAYS)).ToString("C");
}
private void btnReset_Click(object sender, EventArgs e)
{
//unchecks all radio buttons as well as clears out the previous calculations
lblRegistrationCost.Text = "";
lblLodgingCost.Text = "";
lblTotalCost.Text = "";
rbtHandlingStress.Checked = false;
rbtSupervisionSkills.Checked = false;
rbtTimeManagement.Checked = false;
rbtAustin.Checked = false;
rbtChicago.Checked = false;
rbtDallas.Checked = false;
}
}