Skip to content

Instantly share code, notes, and snippets.

@AbdiElmi
Created January 28, 2013 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbdiElmi/4654722 to your computer and use it in GitHub Desktop.
Save AbdiElmi/4654722 to your computer and use it in GitHub Desktop.
[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