Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
[01/28/13] Challenge #119 [Easy] Change Calculator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChangeCalculator
{
class Program
{
static int quarter = 0;
static int dime = 0;
static int nickel = 0;
static int penny = 0;
static void Main(string[] args)
{
Console.Write("Enter Amount ($): ");
string input = Console.ReadLine();
decimal input_amount;
bool result = Decimal.TryParse(input, out input_amount);
Change(input_amount * 100);
Console.WriteLine("Quarterers: " + quarter + "\nDimes: " + dime + "\nNickels: " + nickel + "\nPennies: " + penny);
Console.ReadLine();
}
//Recursive (i think) Change() method, accepting 1 argument(decimal amount)
static void Change(decimal amount)
{
if (amount >= 25)
{
amount = amount - 25;
quarter++;
Change(amount);
}
else if (amount >= 10)
{
amount = amount - 10;
dime++;
Change(amount);
}
else if (amount >= 5)
{
amount = amount - 5;
nickel++;
Change(amount);
}
else if (amount >= 1)
{
amount = amount - 1;
penny++;
Change(amount);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.