Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
GetChange
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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); } } }
Show compiler warnings
[
+
]
Show input
edit mode
|
history
|
discussion