Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
GetChange
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { class Program { public void GetDollarChange(decimal change) { var bills = new[] { // ordered new { name = "twentie(s)", nominal = 20 }, new { name = "ten(s)", nominal = 10 }, new { name = "five(s)", nominal = 5}, new { name = "one(s)", nominal = 1} }; Console.WriteLine("*** Bill denominations ***"); foreach (var bill in bills ) { int count = (int)( change / bill.nominal); change -= count * bill.nominal; Console.WriteLine("Number of {0}: {1}", bill.name, count ); } } public void GetCoinChange(decimal change) { var coins = new[] { // ordered new { name = "quarter(s)", nominal = 0.25m }, new { name = "dime(s)", nominal = 0.10m }, new { name = "nickel(s)", nominal = 0.05m }, new { name = "pennies", nominal = 0.01m } }; Console.WriteLine("*** Coin denominations ***"); foreach (var coin in coins) { int count = (int)(change / coin.nominal); change -= count * coin.nominal; Console.WriteLine("Number of {0}: {1}", coin.name, count); } } static void Main(string[] args) { decimal amount = 19.55m; if (args.Length > 0) { amount = Convert.ToDecimal(args[0]); } var billChange = (decimal)amount / 1; var coinChange = (decimal)amount % 1; Program p = new Program(); p.GetDollarChange(billChange); p.GetCoinChange(coinChange); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Collatz Conjecture Using Pi
Robot_Testing
binary search tree (insert, search, findmin, findmax, level-pre-in-post order traversals
congtodien
4.1 Composition
Interface constraints in generics
Factory Method Design Pattern
prettier Tasty
12 და 14 მარტს დამუშავებული
Non Generic object based class
Please log in to post a comment.