Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi My requirement was like this
For 3 hrs=10$,6hrs=20$...For 24hrs=200$
how can I calculate amount for 2.25 days ?

Thanks in advance..
Posted
Comments
Rahul Rajat Singh 5-Jun-12 4:35am    
is it not a similar to the question you have asked earlier?


how-to-calculate-Amount-based-on-number-of-hours.
Manfred Rudolf Bihy 5-Jun-12 8:14am    
Changed URL to clickable link!

Thanks Rahul for digging up the repost! :thumbsup:
Manfred Rudolf Bihy 5-Jun-12 8:22am    
I'm not sure if you got your requirements correctly.
3h => 10$
6h => 20$ (2 * 3h => 20$)
24h => 200$ (8 * 3h => 200$)

The part with the 24h amounting to 200$ really gets my goat.

Do explain, please!

It has nothing to do with C/C#. Its grade 5 mathematics.

2.25 Days => 2 * 24 hrs + 24/4 hrs => 2 * 24 hrs + 6 hrs => $200 * 2 + $20 => $420
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 5-Jun-12 4:44am    
Wow Manas! Not fit in grade 5 mathematics?
2 days == 24h. *points finger* Ha ha!

I hope you're not serious! ;P

Better fix that fast!
Manas Bhardwaj 5-Jun-12 4:47am    
Hahaha...my bad :(
Manfred Rudolf Bihy 5-Jun-12 4:51am    
That's better! 5+
;)
Manas Bhardwaj 5-Jun-12 4:55am    
Thanks :)
sandeep nagabhairava 5-Jun-12 4:58am    
hi i need a formula for that...
It really depends on how you look at it:

  1. You could do an analysis and calculate the interpolated price.
  2. You could say that 2.25 days is 2 * 24h plus 1 * 6h (6h/24h == 0.25)
    So the price would be 2 * 200$ + 1 * 20$ == 420$


Actually the price of 200$ for 24 hours doesn't make any sense since 8 three hour tickets cost 80$ which is the same as 4 six hour tickets. So instead of buying two 24 hour tickets and one 6 hour ticket just buy 9 six hour tickets and only pay 180$.

Cheers!
 
Share this answer
 
v2
Comments
Manas Bhardwaj 5-Jun-12 4:48am    
This is accurate +5!
sandeep nagabhairava 5-Jun-12 5:00am    
hi i need formula for calculating this type of function
Sandeep Mewara 5-Jun-12 5:15am    
You mean to say, "spoon feed"?
Manfred Rudolf Bihy 5-Jun-12 8:12am    
Thanks! :)
Sandeep Mewara 5-Jun-12 5:16am    
5! Good answer with logic to save money ;)
Here is a bit of code you so eagerly yearned for:

C#
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900