I'm making a basic program to solve the sides of a right-angled triange. I us if statements as demonstrated below and I keep getting this error message:
(It's in Icelandic, but I didn't want to translate the code to be sure everything I see, you see)
Hvada hlid viltu finna? skammhlid
hlid = skammhlid
error: hlidar: mx_el_eq: nonconformant arguments (op1 is 1x9, op2 is 1x8)
error: called from:
error: C;\aefingar\hlidar.m line 10, column 1
Translation: Hvada hlid viltu finna? skammhlid = What side do you want to solve for? shortside
hlid = side, skammhlid = shortside
error: hlidar (hlidar is the file name, means: sides)
Here is the code:
%---------------------------
% (Names)
% Lausn hliða í
% rétthyrndum þríhyrningi
%----------------------------
clc
hlid=input('Hvada hlid viltu finna? ', 's')
if hlid =='langhlid';
b=input('Fyrri skammhlid: ');
a=input('Seinni skammhlid: ');
c=sqrt(a^2+b^2);
printf('Langhlidin er: %f \n', c)
elseif hlid =='skammhlid';
b=input('Hin skammhlidin: ');
c=input('Langhlidin er: ');
a=sqrt(c^2-b^2)
printf('Skammhlidin er: %f \n', a)
endif
Fyrri skammhlid = first short side
Seinni skammhlid = second short side
Langhlidin er = the long side is
Hin skammhlidin = the other short side
Skammhlidin er = the short side is
It works perfectly if I type: langhlid to solve for the long side, but if I type skammhlid to solve for the short sides, the error pops up.
I solved this problem using the switch and {case}, but I'm trying to figure out why if does not work.
Note: I tried writing skammhlid, skamhlid to make the letters 8, instead of 9, didn't work...
Help!
(It's in Icelandic, but I didn't want to translate the code to be sure everything I see, you see)
Hvada hlid viltu finna? skammhlid
hlid = skammhlid
error: hlidar: mx_el_eq: nonconformant arguments (op1 is 1x9, op2 is 1x8)
error: called from:
error: C;\aefingar\hlidar.m line 10, column 1
Translation: Hvada hlid viltu finna? skammhlid = What side do you want to solve for? shortside
hlid = side, skammhlid = shortside
error: hlidar (hlidar is the file name, means: sides)
Here is the code:
%---------------------------
% (Names)
% Lausn hliða í
% rétthyrndum þríhyrningi
%----------------------------
clc
hlid=input('Hvada hlid viltu finna? ', 's')
if hlid =='langhlid';
b=input('Fyrri skammhlid: ');
a=input('Seinni skammhlid: ');
c=sqrt(a^2+b^2);
printf('Langhlidin er: %f \n', c)
elseif hlid =='skammhlid';
b=input('Hin skammhlidin: ');
c=input('Langhlidin er: ');
a=sqrt(c^2-b^2)
printf('Skammhlidin er: %f \n', a)
endif
Fyrri skammhlid = first short side
Seinni skammhlid = second short side
Langhlidin er = the long side is
Hin skammhlidin = the other short side
Skammhlidin er = the short side is
It works perfectly if I type: langhlid to solve for the long side, but if I type skammhlid to solve for the short sides, the error pops up.
I solved this problem using the switch and {case}, but I'm trying to figure out why if does not work.
Note: I tried writing skammhlid, skamhlid to make the letters 8, instead of 9, didn't work...
Help!