案例6
:查询自动售货机中商品的价格
步骤:
其代码如下;
{
if (RadioButton1.Checked)
{
Label1.Text = RadioButton1.Text + "的价格是:3万";
}
else if (RadioButton2.Checked)
{
Label1.Text = RadioButton2.Text + "的价格是:4万";
}
else if (RadioButton3.Checked)
{
Label1.Text = RadioButton3.Text + "的价格是:5万";
}
else if (RadioButton4.Checked)
{
Label1.Text = RadioButton4.Text + "的价格是:6万";
}
else
{
Label1.Text = "请选择商品";
}
}
}
案例7
:商品打折查询
步骤:
其代码如下;
{
double huafei = 0;
if (TextBox1.Text == "")
{
Label1.Text = "请输入你所购物的总金额";
}
else
{
{
huafei = Convert.ToDouble(TextBox1.Text);
}
double shifu;
if (CheckBox1.Checked)
{
if (huafei >= 5000)
{
shifu = huafei * 0.55 * 0.95;
Label1.Text = shifu.ToString();
}
else if (huafei >= 2000)
{
shifu = huafei * 0.7 * 0.95;
Label1.Text = shifu.ToString();
}
else if (huafei >= 1000)
{
shifu = huafei * 0.8 * 0.95;
Label1.Text = shifu.ToString();
}
else if (huafei >= 500)
{
shifu = huafei * 0.9 * 0.95;
Label1.Text = shifu.ToString();
}
else if (huafei < 500)
{
shifu = huafei * 0.95;
Label1.Text = shifu.ToString();
}
else
{
Label1.Text = "请输入你所购物的总金额";
}
}
else
{
if (huafei >= 5000)
{
shifu = huafei * 0.55;
Label1.Text = shifu.ToString();
}
else if (huafei >= 2000)
{
shifu = huafei * 0.7;
Label1.Text = shifu.ToString();
}
else if (huafei >= 1000)
{
shifu = huafei * 0.8;
Label1.Text = shifu.ToString();
}
else if (huafei >= 500)
{
shifu = huafei * 0.9;
Label1.Text = shifu.ToString();
}
else if (huafei < 500)
{
shifu = huafei;
Label1.Text = shifu.ToString();
}
else
{
Label1.Text = "请输入你所购物的总金";
}
}
}
}
}
案例8
:计算并显示通话费用
步骤:
其代码如下;
{
int shijian = 0;
if (TextBox1.Text == "")
{
Label1.Text = "请输入你的通话时间";
}
else
{
shijian = Convert.ToInt32(TextBox1.Text);
}
double huafei;
if (RadioButton1.Checked)
{
if (TextBox1.Text == "")
{
Label1.Text = "请输入你的通话时间";
}
else if (shijian > 3)
{
huafei = 0.25 + (shijian - 3) * 0.15;
Label1.Text = huafei.ToString();
}
else
{
huafei = 0.25;
Label1.Text = huafei.ToString();
}
}
else if (RadioButton2.Checked)
{
if (TextBox1.Text == "")
{
Label1.Text = "请输入你的通话时间";
}
else
{
huafei = shijian * 0.35;
Label1.Text = huafei.ToString();
}
}
else if (RadioButton3.Checked)
{
if (TextBox1.Text == "")
{
Label1.Text = "请输入你的通话时间";
}
else
{
huafei = shijian * 1.10;
Label1.Text = huafei.ToString();
}
}
else
{
if (TextBox1.Text == "")
{
Label1.Text = "请输入你的通话时间" + "请选择你的通话类型";
}
else
{
Label1.Text = "请选择你的通话类型";
}
}
}
}