為鐵路編寫計算運費的程序。假設(shè)鐵路托運行李,規(guī)定每張客票托運費的計算方法是: 行李重量不超過 50 kg時,每千克0.25元;超過 50 kg而不超過 120 kg時,其超過部分每千克0.35元;超過 120 kg時,其超過部分每千克0.45元。
為鐵路編寫計算運費的程序。假設(shè)鐵路托運行李,規(guī)定每張客票托運費的計算方法是: 行李重量不超過 50 kg時,每千克0.25元;超過 50 kg而不超過 120 kg時,其超過部分每千克0.35元;超過 120 kg時,其超過部分每千克0.45元。
2022-06-10
namespace ConsoleApplication1
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("Please enter the weight:");
? ? ? ? ? ? double sum;
? ? ? ? ? ? int Weight = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? if (Weight <= 50)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = Weight * 0.25;
? ? ? ? ? ? }
? ? ? ? ? ? else if (Weight <= 120)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = 50 * 0.25 + (Weight-50) * 0.35;
? ? ? ? ? ? }
? ? ? ? ? ? else?
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = 50 * 0.25 + 70 * 0.35 + (Weight - 120) * 0.45;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine(sum);
? ? ? ? }
? ? }
}
2020-03-28
Console.WriteLine("請問你帶了多少行李(kg):");
? ? ? ? ? ? double sum;
? ? ? ? ? ? int xl = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? if (xl <= 50)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = xl * 0.25;
? ? ? ? ? ? }
? ? ? ? ? ? else if (xl <= 120)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = 50 * 0.25 + (xl - 50) * 0.35;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = 50 * 0.25 + (xl - 50) * 0.45;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine(sum);
? ? ? ? ? ? Console.ReadKey();
2020-03-11