c# - Upchanging (fictional) money -


In a game that uses the age-old monetary system of copper, silver, gold and platinum, where each of 100 The Units Sect is equal to 1 unit of the next highest denomination, is it the acceptable medium of 'sorting' or 'up-changing' on input?

  Public Structure Coin {Private Ent _copper; Private intake; Private int_gold; Private intlatinum; Public int copper {get {return _copper; } Set {int val = value; While (val> 99) {val - = 100; Silver ++; } _copper + = val; }} Get public IV silver {return {_silver}; } Set {int val = value; While (val> 99) {val - = 100; Gold ++; } _silver + = val; }} Public int Gold {get_gold; } Set {int val = value; While (val> 99) {val - = 100; Platinum ++; } _gold + = val; }} Public at Platinum {Receipt {return _platinum; } Set {_platinum = value; }}}  

So much so that although any denomination (less than platinum) I input, will it change money for me correctly? Is there a bad idea to set up such properties? Is this a more efficient method to do in the same method?

Thank you.

OK - so I have commented that I will store it as a value and you want Display though, though. Below is a quick and dirty implementation for an idea. I have not bothered to check negative or optimize - just want to fill in the idea.

  public class coin {public long copper {received; Set; } Public override string toasting () {long change = copper; Var sect = new [] {"gold", "silver"}; Int Numberoff Dynamominus = Sect. Calculation (); Var result = new stringbiller (); Foreign currency (different denominations in sects) {inti coprocertoreente denomination = ((int) math po (100, number of denomination)); Long-term current = change / copperstock deviation; Result. Changed format ("{0}: {1}", denomination, current, current); Change - = (Current amount * Correspondence denomination); NumberOfDenominations--; } result. AppendFormat ("Copper: {0}", change); Return result. Toasting (); }}  

Comments