public static void MainMethod() { long s = 6; // Change this value to perform other tests ChangeOld m = ChangeOld.OptimalChange(s); Console.WriteLine("Coin(s) 2€: " + m.coin2); Console.WriteLine("Bill(s) 5€: " + m.bill5); Console.WriteLine("Bill(s) 10€: " + m.bill10); long result = m.coin2 * 2 + m.bill5 * 5 + m.bill10 * 10; Console.WriteLine("\nChange given = " + result); }
public static ChangeOld GetChange(long s, int?d = null) { if (d.HasValue) { ChangeOld c = new ChangeOld(); c.coin2 = long.Parse((s / d).ToString().Split('.')[0]); return(c); } else { ChangeOld c = new ChangeOld(); c.bill10 = long.Parse((s / 10).ToString().Split('.')[0]); c.bill5 = long.Parse(((s - c.bill10 * 10) / 5).ToString().Split('.')[0]); c.coin2 = (int)(s - (c.bill10 * 10 + c.bill5 * 5)) / 2; return(c); } }