mirror of
https://github.com/dotnet/intro-to-dotnet-web-dev.git
synced 2025-12-06 05:32:03 +01:00
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:
parent
7cba5db2a8
commit
a50d77b82f
|
|
@ -17,7 +17,6 @@ is used to ensure that logic in the MakeChange method is working as
|
||||||
expected.
|
expected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
string? readResult = null;
|
string? readResult = null;
|
||||||
bool useTestData = false;
|
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)
|
static void MakeChange(int cost, int[] cashTill, int twenties, int tens = 0, int fives = 0, int ones = 0)
|
||||||
{
|
{
|
||||||
cashTill[3] += twenties;
|
int availableTwenties = cashTill[3] + twenties;
|
||||||
cashTill[2] += tens;
|
int availableTens = cashTill[2] + tens;
|
||||||
cashTill[1] += fives;
|
int availableFives = cashTill[1] + fives;
|
||||||
cashTill[0] += ones;
|
int availableOnes = cashTill[0] + ones;
|
||||||
|
|
||||||
int amountPaid = twenties * 20 + tens * 10 + fives * 5 + ones;
|
int amountPaid = twenties * 20 + tens * 10 + fives * 5 + ones;
|
||||||
int changeNeeded = amountPaid - cost;
|
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))
|
while ((changeNeeded > 19) && (cashTill[3] > 0))
|
||||||
{
|
{
|
||||||
cashTill[3]--;
|
availableTwenties--;
|
||||||
changeNeeded -= 20;
|
changeNeeded -= 20;
|
||||||
Console.WriteLine("\t A twenty");
|
Console.WriteLine("\t A twenty");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((changeNeeded > 9) && (cashTill[2] > 0))
|
while ((changeNeeded > 9) && (cashTill[2] > 0))
|
||||||
{
|
{
|
||||||
cashTill[2]--;
|
availableTens--;
|
||||||
changeNeeded -= 10;
|
changeNeeded -= 10;
|
||||||
Console.WriteLine("\t A ten");
|
Console.WriteLine("\t A ten");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((changeNeeded > 4) && (cashTill[1] > 0))
|
while ((changeNeeded > 4) && (cashTill[1] > 0))
|
||||||
{
|
{
|
||||||
cashTill[1]--;
|
availableFives--;
|
||||||
changeNeeded -= 5;
|
changeNeeded -= 5;
|
||||||
Console.WriteLine("\t A five");
|
Console.WriteLine("\t A five");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((changeNeeded > 0) && (cashTill[0] > 0))
|
while ((changeNeeded > 0) && (cashTill[0] > 0))
|
||||||
{
|
{
|
||||||
cashTill[0]--;
|
availableOnes--;
|
||||||
changeNeeded -= 1;
|
changeNeeded -= 1;
|
||||||
Console.WriteLine("\t A one");
|
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)
|
if (changeNeeded > 0)
|
||||||
throw new InvalidOperationException("InvalidOperationException: The till is unable to make change for the cash provided.");
|
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)
|
static void LogTillStatus(int[] cashTill)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue