I wrote a MATLAB script to ask users to choose one of the shape and calculate the area of the shape.
My script is as follows. I can run with circle and square, but others cannot. I think it's the number of alphabet problem.
Any method to solve this??
fprintf('Choose one of the following to find the area: \n 1. circle \n 2. square \n 3. trapezium \n 4. triangle \n 5. rectangle \n');
s=input('Please choose one of the shape: ', 's');
if s=='circle'
r=input('Enter the radius of the circle(cm):');
area=(4/3)*pi*r;
fprintf('The area of the circle is %.4f cm^2. \n', area);
elseif s=='square'
a=input('Enter the length of one side(cm): ');
area=a*a;
fprintf('The area of square is %.4fcm^2. \n', area);
elseif s=='trapezium'
a=input('Enter the length of the first parallel side(cm): ');
b=input('Enter the length of another parallel side(cm): ');
h=input('Enter the perpendicular distance between the pair of parallel sides(cm): ');
area=0.5*(a+b)*h;
fprintf('The area of trapezium is %.4fcm^2. \n', area);
elseif s=='triangle'
b=input('Enter the length of the base(cm): ');
h=input('Enter the length of the height(cm): ');
area=0.5*h*b;
fprintf('The area of triangle is %.4fcm^2. \n', area);
elseif s=='rectangle'
a=input('Enter the length of one side(cm): ');
b=input('Enter the length of another side(cm): ');
area=a*b;
fprintf('The area of rectangle is %.4fcm^2. \n', area);
else
disp('Please choose again.');
end