Created
January 28, 2013 11:20
-
-
Save AbdiElmi/4654722 to your computer and use it in GitHub Desktop.
[01/28/13] Challenge #119 [Easy] Change Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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