MATLAB: I cant find the fault in the code

if statementloopsstrings

i have this code: function T=convertTemperature(T,unitFrom,unitTo)
Celcius='Celcius';
Fahrenheit='Fahrenheit';
Kelvin='Kelvin';
if strcmpi(unitFrom,Celcius) && strcmpi(unitTo,Fahrenheit)
T=1.8*T+32;
elseif strcmpi(unitFrom,Celcius) && strcmpi(unitTo,Kelvin)
T=T+273.15;
elseif strcmpi(unitFrom,Fahrenheit) && strcmpi(unitTo,Celcius)
T=(T-32)/1.8;
elseif strcmp(unitFrom,Fahrenheit) && strcmp(unitTo,Kelvin)
T=(T+459.67)/1.8;
elseif strcmp(unitFrom,Kelvin) && strcmp(unitTo,Celcius)
T=T-273.67; elseif strcmp(unitFrom,Kelvin) && strcmp(unitTo,Fahrenheit)
T=1.8*T+459.67;
end
for some reason when i put in convertTemperature(10, 'Celsius','Fahreheit') i get the right result (50) but when i enter convertTemperature(50, 'Fahrenheit', 'Celsius') it just gives me 50 where it should give me 10. can anybody notice what i did wrong. thanks in advance

Best Answer

It is because you misspelled BOTH Celsius and Fahrenheit. Check your spelling - or at least be consistent in how you mispell them.
Related Question