Add feat: finished debugging the challenge, created a variable in the MakeChange method to hold the total ammount of types of bills I have combining the twenties, tens, etc arguments with their corresponmding cashTill values. Depending on amount of change needed via the while loops will incrementally subtract those available variables once finished with while loops will directly change the amount of bills in cashTill elements to the available bills left.

This commit is contained in:
Isaac Alter 2023-07-23 16:56:05 -06:00
parent 7cba5db2a8
commit a50d77b82f
2 changed files with 14 additions and 10 deletions

View file

@ -17,7 +17,6 @@ is used to ensure that logic in the MakeChange method is working as
expected.
*/
string? readResult = null;
bool useTestData = false;
@ -115,10 +114,10 @@ static void LoadTillEachMorning(int[,] registerDailyStartingCash, int[] cashTill
static void MakeChange(int cost, int[] cashTill, int twenties, int tens = 0, int fives = 0, int ones = 0)
{
cashTill[3] += twenties;
cashTill[2] += tens;
cashTill[1] += fives;
cashTill[0] += ones;
int availableTwenties = cashTill[3] + twenties;
int availableTens = cashTill[2] + tens;
int availableFives = cashTill[1] + fives;
int availableOnes = cashTill[0] + ones;
int amountPaid = twenties * 20 + tens * 10 + fives * 5 + ones;
int changeNeeded = amountPaid - cost;
@ -130,28 +129,28 @@ static void MakeChange(int cost, int[] cashTill, int twenties, int tens = 0, int
while ((changeNeeded > 19) && (cashTill[3] > 0))
{
cashTill[3]--;
availableTwenties--;
changeNeeded -= 20;
Console.WriteLine("\t A twenty");
}
while ((changeNeeded > 9) && (cashTill[2] > 0))
{
cashTill[2]--;
availableTens--;
changeNeeded -= 10;
Console.WriteLine("\t A ten");
}
while ((changeNeeded > 4) && (cashTill[1] > 0))
{
cashTill[1]--;
availableFives--;
changeNeeded -= 5;
Console.WriteLine("\t A five");
}
while ((changeNeeded > 0) && (cashTill[0] > 0))
{
cashTill[0]--;
availableOnes--;
changeNeeded -= 1;
Console.WriteLine("\t A one");
}
@ -159,6 +158,11 @@ static void MakeChange(int cost, int[] cashTill, int twenties, int tens = 0, int
if (changeNeeded > 0)
throw new InvalidOperationException("InvalidOperationException: The till is unable to make change for the cash provided.");
cashTill[3] = availableTwenties;
cashTill[2] = availableTens;
cashTill[1] = availableFives;
cashTill[0]= availableOnes;
}
static void LogTillStatus(int[] cashTill)

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>