disp('Total cost in $')a=0.5;b=0.3;c=0.2;x=input('Enter the travel distance (km): ');if x<=100 cost=x*aelseif 100<x<=300 cost=50+((x-100)*b)else cost=110+((x-300)*c)end
If I input 500 the output will be 170 instead of 150 I don't know why but matlab always counts with the previous formula (elseif 100<x<=300)
Best Answer