📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinApp4_5商品打折
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double money, discount, cutRate=1;
int m;
money = double.Parse(txtMoney.Text);
/* */
if (money >= 5000)
m = 10;
else
m = (int)(money / 500);
// m = (int)(money / 500);
switch(m)
{
case 0: cutRate = 1; break; // money<500元的折扣
case 1: cutRate = .95; break; // 500≤money<1000元的折扣
case 2: cutRate = .9; break; // 以下为1000≤money<3000元的折扣
case 3: cutRate = .9; break;
case 4: cutRate = .9; break;
case 5: cutRate = .9; break;
case 6: cutRate = .85; break; // 以下为3000≤money<5000元的折扣
case 7: cutRate = .85; break;
case 8: cutRate = .85; break;
case 9: cutRate = .85; break;
case 10: cutRate = .8; break; // money≥5000元的折扣
default: MessageBox.Show("金额输入错误!"); return; // 输入错误
//default: cutRate = .8; break; // money≥5000元的折扣
}
discount = money * cutRate;
txtDiscount.Text = discount.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -