This is practice for a separate larger program, just a little console output showing how many of certain values are used. For some reason if I set the final while num value to zero, it won't output anything in the console. If I set it to 20 it will output, count the hundreds and the 20's, but skips the fact that there is a 50 because the while value won't allow it to go below 20. I tried while num is >= to zero as well. At > zero or >=, I would expect it would count the 50 and output 4 100's, 1 50 and 0 20's. I arbitrarily set the while value to 10 and it still gave 2 20's and the hundreds, but set at 1 it didn't output again, same as when set to zero. Before I can incorporate the logic into the bigger program which has a lot more values and returns I imagine I'll need to understand where I'm failing. I looked into recursion and trackback algorithms and they were just a bit beyond where I'm at yet. I did wonder if I could use modulus too. That's off track tho, I'm most curious about why that while value won't allow itself to be set to greater than or greater than/equal to zero.
using System;
namespace dollars_back_test
{
class Program
{
static void Main(string[] args)
{
int num = 450, hundos = 0, fifties = 0, twenties = 0;
do
{
if (num > 100)
{
num -= 100;
hundos++;
}
else if (num > 50)
{
num -= 50;
fifties++;
}
else if (num > 20)
{
num -= 20;
twenties++;
}
} while (num > 20);
Console.WriteLine($"Dispensing {hundos} 100's, {fifties} 50's, {twenties} 20's.");
Console.ReadLine();
}
}
}