Breaking down currency in c#
Posted
by Thatguy
on Stack Overflow
See other posts from Stack Overflow
or by Thatguy
Published on 2010-04-12T06:46:59Z
Indexed on
2010/04/12
6:53 UTC
Read the original article
Hit count: 352
c#
i'm trying to get this program to break down a user defined amount of dollars into the fewest possible bills. i don't think my for loops are running because if i put a writeline line in them it doesn't show up when i run it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the amount of money: $");
int totalAmount = Convert.ToInt32(Console.ReadLine());
calculateNumberOfBills(totalAmount);
}
static void calculateNumberOfBills(int totalAmount)
{
int[] denominations = { 20, 10, 5, 1 };
int[] numberOfBills = new int[4];
for (numberOfBills[0] = 0; totalAmount < 20; numberOfBills[0]++)
{
totalAmount = totalAmount - 20;
}
for (numberOfBills[1] = 0; totalAmount < 10; numberOfBills[1]++)
{
totalAmount = totalAmount - 10;
}
for (numberOfBills[2] = 0; totalAmount < 5; numberOfBills[2]++)
{
totalAmount = totalAmount - 5;
}
for (numberOfBills[3] = 0; totalAmount <= 0; numberOfBills[3]++)
{
totalAmount = totalAmount - 1;
}
Console.WriteLine("Number of twenties" + numberOfBills[0]);
Console.WriteLine("Number of tens" + numberOfBills[1]);
Console.WriteLine("Number of fives" + numberOfBills[2]);
Console.WriteLine("Number of ones" + numberOfBills[3]);
}
}
}
© Stack Overflow or respective owner