# what is wrong with my script

3 views (last 30 days)
Jordan Birley on 4 Dec 2019
Commented: Stephan on 4 Dec 2019
clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from')
if units == mm
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
end
if units == cm
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
end
if units == m
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end

Stephan on 4 Dec 2019
clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from','s')
if units == 'mm'
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
end
if units == 'cm'
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
end
if units == 'm'
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end

Jordan Birley on 4 Dec 2019
%But i want it to only display the selected units answers. how do i do more than on else statments for the same if
clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from','s')
if units == 'mm'
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
else units == 'cm'
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
else units == 'm'
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end
Stephan on 4 Dec 2019
clear all
for loop_index = 1:2
x = input('Input number to convert:\n');
units = string(input('Input the units to convert from:\n','s'))
if units == "mm"
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
elseif units == "cm"
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
elseif units == "m"
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
else
disp('Please choose a correct unit to convert from.')
end
end