My friend suggested another way of doing it: "Start with the highest denomination you want to give out, say $100s, and then go through a loop repeatedly subtracting $100 until you get a negative number, at which point you've reached the max number of hundreds. Then you move down to the next denomination."
Made perfect sense to me, so I came up with:
Code:
double money = 0;
string name1 = "Jordan"; // , name2 = "", name3 = "";
Console.WriteLine("How much did " + name1 + " make?");
Console.Write("$");
money = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Converting {0:C} into change ...", money);
int h = -1;
while (money >= 0)
{
money = money - 100;
h++;
}
Console.WriteLine("Hundreds: "+ h +"");
And it works perfectly! My next question, though, is how do I take what's left over before you hit a negative number, and find out how many fifties it takes to make that up?