你好!!
static void Main(string[] args)
{
Console.WriteLine("*****飞机行李托运计费系统*****");
Console.Write("\n请输入行李重量:");
double a = double.Parse(Console.ReadLine());
if(a <= 20)
Console.Write("\n可以免费带上飞机\n");
if (a > 20 && a <= 30)
Console.Write("\n行李超重 "+(a-20)+" 公斤,支付行李费 " +(a-20)*30 +" 元\n");
if (a > 30 && a <= 40)
Console.Write("\n行李超重 "+(a-20)+" 公斤,支付行李费 "+((a-30)*40+300)+" 元\n");
if (a > 40 && a <= 50)
Console.Write("\n行李超重 "+(a-20)+" 公斤,支付行李费 "+((a-40)*40+300+400)+" 元\n");
if (a > 50)
Console.Write("\n行李超过 50 公斤,不能随身携带\n");
int.Parse(Console.ReadLine());
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入物品重量");
string value;
while ((value = Console.ReadLine()) != "")
{
checkweight(value);
}
Console.WriteLine("请按任意键退出!");
Console.ReadKey();
}
public static void checkweight(string value)
{
float weight = 0;
float total = 0;
if (float.TryParse(value, out weight))
{
if (weight < 20)
{
Console.WriteLine("20公斤以下免费托运!");
}
else if (weight >= 20 & weight < 30)
{
total = 30 * (weight - 20);
Console.WriteLine("20~30公斤超出部分30元/公斤,合计:" + total);
}
else if (weight >= 30 & weight < 40)
{
total = 10 * 30 + 40 * (weight - 30);
Console.WriteLine("30~40公斤超出部分40元/公斤,合计:" + total);
}
else if (weight >= 40 & weight < 50)
{
total = 10 * 30 + 40 * 10 + 50 * (weight - 40);
Console.WriteLine("40~50公斤超出部分50元/公斤,合计:" + total);
}
else
{
Console.WriteLine("50公斤以上不允许个人携带!");
}
}
else
{
Console.WriteLine("物品重量必须为数字!");
}
Console.WriteLine("请继续输入!");
}
}
}
运行效果截图:这个也就是绕一点不是很繁琐。你这个题意不是很明确,
我的收费标注是:如果是42公斤超出了22公斤应该是有10公斤按照30算 12公斤按照40算对吧?
所以四十公斤的话是10*30+10*40 =700
static void Main(string[] args)
{
Console.WriteLine("请输入行李的重量(公斤):");
double weight = Convert.ToDouble(Console.ReadLine());//获取行李重量
double flag = weight - 20;//行李与标准(20)的差额
if (flag < 0)//<20公斤
{
Console.WriteLine("可以免费携带");
}
else
{
if (flag < 10)//20-30公斤
{
Console.WriteLine("需要交行李费" + (flag * 30) + "元");
}
else
{
if (flag < 20)//30-40公斤
{
double money = 10 * 30 + (flag - 30) * 40;
Console.WriteLine("需要交行里费" + money + "元");
}
else
{
Console.WriteLine("您的行李超重,不允许携带");
}
}
}
Console.ReadLine();
}
}
if (a > 30 && a <= 40) Console.Write("\n行李超重 "+(a-20)+" 公斤,支付行李费 "+((a-30)*40+300)+" 元\n"); if (a > 40 && a <= 50) Console.Write("\n行李超重 "+(a-20)+" 公斤,支付行李费 "highlight">a-40)*40+300+400)+" 元\n");飞机行李大于40和小于等于50的时候超出部分为50元每千克,故您的答案我个人认为有一小部分错误。