您的位置:首页 > 编程语言 > C#

c#设计简单飞机行李托运计费系统

2019-03-20 09:25 3847 查看
版权声明:©2018-2020 Macromedia, Inc. All rights reserved. 文章为时间的荒野所原创如需转载请联系博主。 https://blog.csdn.net/qq_43444398/article/details/88680259 利用C#的if……else语句设计简单的飞机行李托运计费系统,程序运行效果图如下,这里假设飞机上个人拖运行李的条件是:行李重量在20公斤以下,免费托运;20 ~ 30公斤超出部分30元、公斤;30-40公斤超出部分40元/公斤;40 ~ 50公斤超出部分50元/公斤;50公斤公斤以上不允许个人携带。

下面是程序运行效果图:
下面是代码;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 飞机行李托运
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double Zhong, price;//定义重量  和  运费
Zhong = Convert.ToDouble(textBox1.Text.Trim());//将输入值赋给重量
if (Zhong < 0)
{
MessageBox.Show("输入的数据有误!", "计费");//重量小于0
}
else if (Zhong <= 20)
{
MessageBox.Show("免费托运行李!", "计费");//重量小于20
}

else if (Zhong <= 30)
{
price = (Zhong - 20) * 30;
MessageBox.Show("托运费用为" + price + "元!");

}
else if (Zhong <= 40)
{
price = (30 - 20) * 30 + (Zhong - 30) * 40;
MessageBox.Show("您的托运费用为" + price + "元!");

}
else if (Zhong <= 50)/
{
price = (30 - 20) * 30 + (40 - 30) * 40 + (Zhong - 40) * 50;
MessageBox.Show("您的托运费用为" + price + "元!");

}
else
{
MessageBox.Show("您托运的行李超出了最高上限,不允许托运!");

}
}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();//退出程序
}
}
}
自律生活第九天。
希望自己自律上瘾。
我不是在简单的编程,而是在创造一个“世界”。

江客:时荒

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐