[JSP] [VBscript] berekening adhv prijsmodel

Pagina: 1
Acties:

  • fatbenny
  • Registratie: April 2001
  • Laatst online: 07-03-2023
Ik wil een prijs kunnen laten berekenen aan de hand een aantal dat een bezoeker opgeeft.

Dit is het prijsmodel.
Page 1: 60 euro
Page 2-100: 1 euro
Page 101-1000: 10 eurocent
Page > 1000: 5 eurocent

Bijvoorbeeld:
120 pagina's kost 60 euro + 99 euro + 2 euro = 161 euro
1500 pagina's kost 60 euro + 99 euro + 89,90 + 25 euro = 273,90 euro

Ik heb op google gezocht en het forum doorgepluisd maar ik kom er niet uit, heeft iemand tips hoe ik dit aan moet pakken?

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 20:40

crisp

Devver

Pixelated

simple rekenvoorbeeldje (javascript, maar dat mag niet uitmaken):
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var aantal = 1500;
var prijs = 0;

if (aantal > 999)
{
    prijs += (aantal - 1000) * 0.05;
    aantal = 999;
}
if (aantal > 100)
{
    prijs += (aantal - 100) * 0.1;
    aantal = 100;
}
if (aantal > 1)
{
    prijs += (aantal - 1) * 1;
    aantal = 1;
}
if (aantal == 1)
{
    prijs += 60;
}

alert(prijs);

Intentionally left blank


Verwijderd

of zo...

JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    function quote(pages)
    {
      var price = 0;

      if (pages > 0)
      {
         price += 60;

         if (pages > 1)
         {
            price += Math.min( pages - 1, 99) * 1;

            if (pages > 100)
            {
                price += Math.min( pages - 100, 900) * 0.10;

                if (pages > 1000)
                {
                    price += (pages - 1000) * 0.05;
                }
            }
         }
      }

      return price;
    }

  • fatbenny
  • Registratie: April 2001
  • Laatst online: 07-03-2023
Bedankt