Here is a bit of code you so eagerly yearned for:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateSomeStrangePricingRequirement
{
class Program
{
public static double CalculatePrice(Double numberOfDaysWithFraction, Double priceOf3HourInterval, Double priceOf24HourInterval)
{
Double retVal = Double.NaN;
Double numberOfWholeDays = Math.Floor(numberOfDaysWithFraction);
Double numberOfThreeHourIntervals = Math.Ceiling((numberOfDaysWithFraction - numberOfWholeDays) * 8);
retVal = numberOfWholeDays * priceOf24HourInterval + numberOfThreeHourIntervals * priceOf3HourInterval;
return retVal;
}
static void Main(string[] args)
{
Double totalCost = CalculatePrice(2.25, 10, 200);
Console.WriteLine("The total cost for {0} days is {1}$", 2.25, totalCost);
}
}
}
The program outputs for 2.25 420$. If you change that to 2.26 another 3 hour interval is started so the price will be 430$.
And by the way, 24h divided by 3 is 8h. Just a little hint in case you were wondering. If you want you can turn the function I wrote into a one liner. Just as an exercise of course.
Have fun!
Manfred