ผมไปหาวิธีเขียนมาครับ เผอิญอยู่ๆอยากเขียน Copy ได้ครับ
decimal[] ary_dec = new decimal[] { 100, 50, 10,5,1 };//แบงค์
List<string> listof_doing = new List<string>();
decimal dec_moneyvalue = 253;//จำนวนเงินรับ
for (int int_i = 0; int_i < ary_dec.Length; int_i++)
{
var dec_money = ary_dec[int_i];
decimal dec_res1 = dec_moneyvalue / dec_money;
decimal mod1 = dec_moneyvalue % dec_money;
string ary_str_doing ="";
if (mod1 > 0)
{
int int_i2 = (int_i + 1);
ary_str_doing = ary_dec[int_i] + " Bath Uses " + Math.Floor(dec_res1) + " Piece";
while (int_i2 <= ary_dec.Length - 1)
{
dec_money = ary_dec[int_i2];
dec_res1 = mod1 / dec_money;
mod1 = mod1 % dec_money;
if (dec_res1 <= 0)
{
break;
}
if (Math.Floor(dec_res1) != 0)
{
ary_str_doing += "," + ary_dec[int_i2] + " Bath Uses " + Math.Floor(dec_res1) + " Piece";
}
int_i2++;
}
listof_doing.Add(ary_str_doing);
Console.WriteLine(ary_str_doing+"\n");
}
else
{
ary_str_doing = ary_dec[int_i] + "Bath Uses " + Math.Floor(dec_res1) + " Piece\n";
listof_doing.Add(ary_str_doing);
Console.WriteLine(ary_str_doing);
}
}
Console.ReadLine();
//var result = listof_doing.ToList();
ไม่มีความคิดเห็น:
แสดงความคิดเห็น