標籤:
/*
輸入利潤I,輸出獎金(if和switch都寫了一個)
獎金計算:超過1000000的部分提1%;超過600000不足1000000的部分提1.5%;超過400000不足600000的部分提3%;超過200000不足400000的部分提5%;超過100000不足200000的部分提7.5%;不足100000的部分提10%
*/
double x, I;
x = 0;
Console.WriteLine("請輸入利潤I(元)");
I = Convert.ToDouble(Console.ReadLine());
if (I<=100000)
{
x=I*0.1;
}
else if (I<=200000)
{
x = (I-100000) * 0.075+100000*0.1;
}
else if (I <= 400000)
{
x = (I - 200000) * 0.05 +100000*0.075+ 100000 * 0.1;
}
else if (I <= 600000)
{
x = (I - 400000) * 0.03+200000*0.05 + 100000 * 0.075 + 100000 * 0.1;
}
else if (I <= 1000000)
{
x = (I - 600000) * 0.015 + 200000 * 0.03 + 200000 * 0.05 + 100000 * 0.075 + 100000 * 0.1;
}
else
{
x = (I - 1000000) *0.01+400000* 0.015 + 200000 * 0.03 + 200000 * 0.05 + 100000 * 0.075 + 100000 * 0.1;
}
Console.WriteLine("獎金是"+x+"元");
Console.ReadLine();
--------------------------------------------
double x,z,I;
int y;
int m1 = 100000, m2 = 200000, m3 = 400000, m4 = 600000, m5 = 1000000;
double n1 = 0.1, n2 = 0.075, n3 = 0.05, n4 = 0.03, n5 = 0.015, n6 = 0.01;
Console.WriteLine("請輸入利潤I(元)");
I = Convert.ToDouble(Console.ReadLine());
x = I / 100000;
y =(int)( I / 100000);
z = x - y;
switch (y)
{
case 0:
x = I * n1;
break;
case 1:
x = (I -m1) * n2 + m1 * n1;
break;
case 2:
x = (I -m2) * n3 + (m2-m1) * n2 + m1 * n1;
break;
case 3:
x = (I - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
case 4:
x = (I - m3) * n4 + (m3 -m2)* n3 + (m2-m1) * n2 + m1 * n1;
break;
case 5:
x = (I -m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
case 6:
x = (I - m4) * n5 + (m4-m3) * n4 + (m3 -m2)* n3 + (m2-m1) * n2 + m1 * n1;
break;
case 7:
x = (I - m4) * n5 + (m4 - m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
case 8:
x = (I - m4) * n5 + (m4 - m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
case 9:
x = (I - m4) * n5 + (m4 - m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
case 10:
x = (I - m5) * n6 + (m5 - m4) * n5 + (m4 - m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
default:
x = (I - m5) * n6 + (m5 - m4) * n5 + (m4 - m3) * n4 + (m3 - m2) * n3 + (m2 - m1) * n2 + m1 * n1;
break;
}
Console.WriteLine("獎金是" + x + "元");
Console.ReadKey();
c# 獎金計算