Hey all.
I'm new to MatLab and currently working my way through MATLAB; a practical introduction to programming and problem solving.
Unfortunately, I can't seem to find an answer book for the exercises, and am wondering if you would be able to help me?
I'm currently trying to write a practice script which calculates the area of a pyramid, with the user entering the height, width and length of the pyramid, and then saying whether this value is in centimetres or inches. The volume should then be displayed in inches.
If the user enters their value in centimetres, I have to convert that value into inches, but i'm having trouble. Here is the script as it stands;
%This script calculates the volume of a pyramid, and requests the user to
%enter the length, width, and height of the pyramid
disp('This programme calculates the volume of a pyramid')
length = input('Enter the length of the base: ');
lengthic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the length from centimetres to inches if necessary
if lengthic == c
length = lengthic/2.54;
end
width = input('Please enter the width of the base: ');
widthic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the width from centimetres to inches if necessary
if widthic == c
width = widthic/2.54;
end
height = input('Enter the height of the pyramid: ');
heightic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the height from centimetres to inches if necessary
if heightic == c
height = heightic/2.54;
end
volume = 1/3*length*width*height;
fprintf('The volume of the pyramid is %.3d', volume)
Would anyone be able to offer any help?
Thanks
I'm new to MatLab and currently working my way through MATLAB; a practical introduction to programming and problem solving.
Unfortunately, I can't seem to find an answer book for the exercises, and am wondering if you would be able to help me?
I'm currently trying to write a practice script which calculates the area of a pyramid, with the user entering the height, width and length of the pyramid, and then saying whether this value is in centimetres or inches. The volume should then be displayed in inches.
If the user enters their value in centimetres, I have to convert that value into inches, but i'm having trouble. Here is the script as it stands;
%This script calculates the volume of a pyramid, and requests the user to
%enter the length, width, and height of the pyramid
disp('This programme calculates the volume of a pyramid')
length = input('Enter the length of the base: ');
lengthic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the length from centimetres to inches if necessary
if lengthic == c
length = lengthic/2.54;
end
width = input('Please enter the width of the base: ');
widthic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the width from centimetres to inches if necessary
if widthic == c
width = widthic/2.54;
end
height = input('Enter the height of the pyramid: ');
heightic = input('Is that length in (i)nches or (c)entimetres?', 's');
%Converts the height from centimetres to inches if necessary
if heightic == c
height = heightic/2.54;
end
volume = 1/3*length*width*height;
fprintf('The volume of the pyramid is %.3d', volume)
Would anyone be able to offer any help?
Thanks