这个算法怎么做
- 提问者网友:我没有何以琛的痴心不悔
- 2021-08-22 01:43
- 五星知识达人网友:蓝房子
- 2021-08-22 02:37
public void GetSalry()
{
double inNum = 0.0, sum = 0.0, lirun = 0.0;
Console.Write("请输入当月利润额(万): ");
try
{
inNum = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("利润额输入错误!");
Console.ReadLine();
return;
}
lirun = (int)inNum / 10000;
if (lirun <= 10)
{
sum = lirun * 0.1;
}
else if (lirun > 10)
{
sum = 1;
if (lirun <= 20)
{
sum += (lirun - 10) * 0.075;
}
else
{
sum += 10 * 0.075;
if (lirun <= 40)
{
sum += (lirun - 20) * 0.05;
}
else
{
sum += 20 * 0.05;
if (lirun <= 60)
{
sum += (lirun - 40) * 0.03;
}
else
{
sum += 20 * 0.03;
if (lirun <= 100)
{
sum += (lirun - 40) * 0.015;
}
else
{
sum += 40 * 0.015 + (lirun - 100) * 0.01;
}
}
}
}
}
Console.WriteLine("当月提成为:" + sum * 10000);
Console.ReadLine();
}
- 1楼网友:西风乍起
- 2021-08-22 03:08
class Program { static void Main(string[] args) { double inNum = 0.0, sum = 0.0, lirun = 0.0; Console.Write("请输入当月利润额: "); inNum = Convert.ToInt32(Console.ReadLine());
lirun = (int)inNum / 10000; if (lirun <= 10) { sum = lirun * 0.1; } if (lirun > 10 && lirun <= 20) { sum += (lirun - 10) * 0.075; } if (lirun > 20 && lirun <= 40) { sum += (lirun - 20) * 0.05; } if (lirun > 40 && lirun <= 60) { sum += (lirun - 40) * 0.03; } if (lirun > 60 && lirun <= 100) { sum += (lirun - 40) * 0.015; } if (lirun > 100) { sum += (lirun-100)*0.01; }
Console.WriteLine("当月提成为:" + sum*10000); Console.ReadKey(); } }
// 测试结果: