根据所覆盖的距离计算价格 [英] Price Calculation based on the distance covered

查看:76
本文介绍了根据所覆盖的距离计算价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算价格
这就是我所拥有的

I need to calculate price this is what i've got

case1:
如果汽车行驶在1-15英里之间第一英里的价格是3英镑,然后每英里的价格将是1.60英镑

case1: if a car travels between 1-15 miles then price for first mile is £3 and then for every mile after it price will be £1.60

所以对于这种情况我正在计算这样的

so for this case i'm calculating like this

miles= 1-15
 rate=1.60;
  emile=miles-1;
  totalprice=miles*passenger*1.60+3;

case2
如果汽车行驶在15-30英里之间,则价格为1.20英镑/英里+上一个公式

case2 if a car travels between 15-30 miles then price will be £ 1.20/mile+previous formula

所以对于这种情况我正在计算这样

so for this case i'm calculating like this

   rate=1.20;
    rate2=1.60;
    cmile=(miles-14)*rate;
    fmile=(14*rate2+3);
    totalprice=cmile+fmile;

案例3:如果汽车行驶在30-50英里之间,那么价格将为1.10英里/英里+两者上一个公式

case3:if a car travels between 30-50 miles then price will be £ 1.10/mile+both previous formula

现在我被困在这里如何计算第三种情况

now i'm stuck here how do i calculate for 3rd case

推荐答案

试试,

var kms = 10;

var price_1 = (kms > 0) ? 3 : 0; kms =  (kms > 0)? kms - 1 :  0;
var price_2 = (kms - 14) > 0 ? (14 * 1.60) : (kms * 1.60); kms = (kms-14)>0 ? kms - 14 : 0;
var price_3 = (kms - 15) > 0 ? (15 * 1.40) : (kms * 1.40); kms = (kms-15)>0 ? kms - 15 : 0;
var price_4 = (kms > 0) ? (kms * 1.20) : 0;


console.log('Total fare would be :' + (price_1 + price_2 + price_3 + price_4));

这篇关于根据所覆盖的距离计算价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆