本人是初学,想问一下一下一个计算打折的程序任何 实现
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
decimal price, discount;
try
{
price = Convert.ToDecimal(Input.Text);
if (price >= 2000)
{
discount = price * 0.8m;
}
else if (price >= 1000 && price < 2000)
{
discount = price * 0.85m;
}
else if (price >= 500 && price < 1000)
{
discount = price * 0.9m;
}
else if (price >= 100 && price < 500)
{
discount = price * 0.95m;
}
discount = Convert.ToDecimal(....);//这里不太会定义
if (discount >= 0)
{
result.Text = String.Format("{0:C}", discount);
}
else
result.Text = "请输入整数";
}
catch
{
result.Text = "输入有错,请重输!";
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
Program.f2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Input.Text = "";
result.Text = "";
}
}
}