Jakub
Loop is returning the completely wrong value.
I am using the Linqpad to test a pricing algorithm but the result at the is completely wrong. Instead of returning the multiplier rate I am getting the normal rate even tho I am hitting the correct if statement... I am very lost with this, ive been staring at the debugger for a while so I hope someone here can point me in the right direction.
output:
Basically the problem I am having is that the return should contain the Multiplier rate since its Sunday and its 19. I'm not really sure why I am stilling getting the normal rate. Ive used the debugger and it seems to be hitting the correct if statement so idk why the value thats getting printed outside the loop is wrong.
var transactionFeePercentage = 5M; // 5% processing fee (adjust as needed)
var processingFeePercentage = 10M; // 10% processing fee (adjust as needed)
var parkingBooking = new DateTime(12, 10, 7, 19, 0, 0);
var duration = TimeSpan.FromHours(2);
var bookingTotalMinutes = duration.TotalMinutes;
var bookingInterval = bookingTotalMinutes / 30;
var pricePerHour = 4M;
var subTotal = 0M;
parkingBooking.DayOfWeek.Dump();
parkingBooking.TimeOfDay.Dump();
for (int i = 0; i < bookingInterval; i++)
{
DateTime currentIntervalStart = parkingBooking.AddMinutes(i * 30);
DateTime currentIntervalEnd = currentIntervalStart.AddMinutes(30);
decimal intervalPrice = (decimal)30 / 60 * pricePerHour; // Calculate price for the current interval
if (currentIntervalStart.Hour >= 7 && currentIntervalStart.Hour < 14)
{
subTotal += intervalPrice; // Normal rate
}
else if ((currentIntervalStart.DayOfWeek == DayOfWeek.Friday || currentIntervalStart.DayOfWeek == DayOfWeek.Saturday)
&& currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21) {
subTotal += intervalPrice * 1.35M;
}
else if (currentIntervalStart.DayOfWeek == DayOfWeek.Sunday && (currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21))
{
subTotal += intervalPrice * 0.5M;
}
else if (currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21) {
subTotal += intervalPrice * 1.15M;
}
else if (currentIntervalStart.Hour >= 14 && currentIntervalStart.Hour < 17)
{
subTotal += intervalPrice * 1.75M; // Rush hour rate (adjust as needed)
}
else
{
subTotal += intervalPrice; // Quiet period rate (adjust as needed)
}
Console.WriteLine($"Normal Rate {subTotal} : Multiplier {subTotal * 0.5M}");
}
var totalCost = subTotal;
var transactionFee = totalCost * (transactionFeePercentage / 100);
var processingFee = totalCost * (processingFeePercentage / 100);
totalCost += transactionFee + processingFee;
Console.WriteLine("Sub Total: " + subTotal);
Console.WriteLine("Total Cost: " + totalCost);
var providerCharge = subTotal * 0.30M;
var providerCut = subTotal - providerCharge;
Console.WriteLine("Provider cut: " + providerCut);
Console.WriteLine("Parklink cut: " + (processingFee + transactionFee + providerCharge));
var transactionFeePercentage = 5M; // 5% processing fee (adjust as needed)
var processingFeePercentage = 10M; // 10% processing fee (adjust as needed)
var parkingBooking = new DateTime(12, 10, 7, 19, 0, 0);
var duration = TimeSpan.FromHours(2);
var bookingTotalMinutes = duration.TotalMinutes;
var bookingInterval = bookingTotalMinutes / 30;
var pricePerHour = 4M;
var subTotal = 0M;
parkingBooking.DayOfWeek.Dump();
parkingBooking.TimeOfDay.Dump();
for (int i = 0; i < bookingInterval; i++)
{
DateTime currentIntervalStart = parkingBooking.AddMinutes(i * 30);
DateTime currentIntervalEnd = currentIntervalStart.AddMinutes(30);
decimal intervalPrice = (decimal)30 / 60 * pricePerHour; // Calculate price for the current interval
if (currentIntervalStart.Hour >= 7 && currentIntervalStart.Hour < 14)
{
subTotal += intervalPrice; // Normal rate
}
else if ((currentIntervalStart.DayOfWeek == DayOfWeek.Friday || currentIntervalStart.DayOfWeek == DayOfWeek.Saturday)
&& currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21) {
subTotal += intervalPrice * 1.35M;
}
else if (currentIntervalStart.DayOfWeek == DayOfWeek.Sunday && (currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21))
{
subTotal += intervalPrice * 0.5M;
}
else if (currentIntervalStart.Hour >= 17 && currentIntervalStart.Hour < 21) {
subTotal += intervalPrice * 1.15M;
}
else if (currentIntervalStart.Hour >= 14 && currentIntervalStart.Hour < 17)
{
subTotal += intervalPrice * 1.75M; // Rush hour rate (adjust as needed)
}
else
{
subTotal += intervalPrice; // Quiet period rate (adjust as needed)
}
Console.WriteLine($"Normal Rate {subTotal} : Multiplier {subTotal * 0.5M}");
}
var totalCost = subTotal;
var transactionFee = totalCost * (transactionFeePercentage / 100);
var processingFee = totalCost * (processingFeePercentage / 100);
totalCost += transactionFee + processingFee;
Console.WriteLine("Sub Total: " + subTotal);
Console.WriteLine("Total Cost: " + totalCost);
var providerCharge = subTotal * 0.30M;
var providerCut = subTotal - providerCharge;
Console.WriteLine("Provider cut: " + providerCut);
Console.WriteLine("Parklink cut: " + (processingFee + transactionFee + providerCharge));
Sunday
19:00:00
Normal Rate 1.00 : Multiplier 0.500
Normal Rate 2.00 : Multiplier 1.000
Normal Rate 3.00 : Multiplier 1.500
Normal Rate 4.00 : Multiplier 2.000
Sub Total: 4.00
Total Cost: 4.6000
Provider cut: 2.8000
Parklink cut: 1.8000
Sunday
19:00:00
Normal Rate 1.00 : Multiplier 0.500
Normal Rate 2.00 : Multiplier 1.000
Normal Rate 3.00 : Multiplier 1.500
Normal Rate 4.00 : Multiplier 2.000
Sub Total: 4.00
Total Cost: 4.6000
Provider cut: 2.8000
Parklink cut: 1.8000
23 replies