daydien789
Thành viên mới

- Tham gia
- 7/1/15
- Bài viết
- 21
- Được thích
- 0
Mình nghĩ mãi chẳng ra cách làm, có ai biết cách làm không giúp mình với 


Dim km, dg1, dg2, tien as long
dg1=11000
dg2=9000
If km <= 1 then
tien = 1*dg1
End if
'Print tien
If km > 1 then
tien = 1*dg1 + (km-1)*dg2
End if
'Print tien
Dim dg1, dg2, dg3, dg4, dg5, tien, sodien as long
Dim t1, t2, t3, t4 as long
dg1 = 500
dg2 = 650
dg3 = 850
dg4=1100
dg3=1300
t1= 50*dg1
t2=t1+50*dg2
t3=t2+ 100*dg3
t4=t3+150*dg4
if sodien<=50 then tien=t1
'print tien
if sodien >50 and sodien <=100 then tien = t1 + (sodien-50)*dg2
'print tien
if sodien >100 and sodien <= 200 then tien = t2 +(sodien - 100)*dg3
'print tien
if sodien >200 and sodien <= 350 then tien = t3 + (sodien - 200)*dg4
'print tien
if sodien > 350 then tien = t4 + (sodien - 350)*dg5
'print tien
Function TienTaxi(soKm As Double) As Double
[COLOR=#008000]' đặc điểm: ngắn gọn
[/COLOR]TienTaxi = IIf(soKm <= 1, 11000, Application.RoundUp(soKm, 0) * 9000 + 2000)
End Function
Function TienDien(soKWh As Double) As Double
[COLOR=#008000]' đặc điểm: lúc cần sửa bậc thang, hoặc thêm bậc thì chỉ việc sửa tham số arrays
[/COLOR]mucBac = Array(0, 50, 50, 100, 150)
mucGia = Array(0, 500, 650, 850, 1100, 1300)
TienDien = 0
For muc = LBound(mucBac) To UBound(mucBac)
soKWh = soKWh - mucBac(muc)
If soKWh <= 0 Then Exit For
TienDien = TienDien + soKWh * (mucGia(muc + 1) - mucGia(muc))
Next muc
End Function
2/ Bài tập 3:
PHP:Dim km, dg1, dg2, tien as long dg1=11000 dg2=9000 If km <= 1 then tien = 1*dg1 End if 'Print tien If km > 1 then tien = 1*dg1 + (km-1)*dg2 End if 'Print tien
3/ Bài tập 4:
PHP:Dim dg1, dg2, dg3, dg4, dg5, tien, sodien as long Dim t1, t2, t3, t4 as long dg1 = 500 dg2 = 650 dg3 = 850 dg4=1100 dg3=1300 t1= 50*dg1 t2=t1+50*dg2 t3=t2+ 100*dg3 t4=t3+150*dg4 if sodien<=50 then tien=t1 'print tien if sodien >50 and sodien <=100 then tien = t1 + (sodien-50)*dg2 'print tien if sodien >100 and sodien <= 200 then tien = t2 +(sodien - 100)*dg3 'print tien if sodien >200 and sodien <= 350 then tien = t3 + (sodien - 200)*dg4 'print tien if sodien > 350 then tien = t4 + (sodien - 350)*dg5 'print tien
Tôi viết chay thế, bạn test thử nhé.
Range("D4").Value = km
Range("E4").Value = tien