Need to write a program that finds the volume and surface area of shapes, askes a user how many shapes they want to find the V and SA of, askes to input values, displays the final values and askes if they are finished. Have this so far, but get error

7 views (last 30 days)
clc clear fprintf('This program will determine the surface area and volume of a right circular cone,\na cylinder, and a rectangular prism. \n \n'); a = 1; while a == 1 n = input('How many objects would you like to find the surface area and volume of? '); shape = input('Enter type of shape (enter cone for right circular cone, cylinder for cylinder,\nrectangle for rectangular prism) : '); if shape == 'cone' r = ('input radius: '); h = ('input height: '); V = pi*r.^2*(h/3); SA = pi*r(r+(h.^2+r.^2)^.5); disp('Volume = ') disp(V) disp('Surface Area = ') disp(SA); else if shape == 'cylinder \n' r = ('input radius'); h = ('input hieght'); V = pi*r.^2*h ; SA = 2*pi*r*h+2*pi*r.^2 ; disp('Volume = ') disp(V) disp('Surface Area = ') disp(SA) else if shape == 'rectangle' l = ('input length'); w = ('input width'); h= ('input hieght'); V=w*l*h ; SA = 2*(w*l+h*l+h*w); disp('Volume = ') disp(V) disp('Surface Area = ') disp(SA) end end end a = input('do you want to continue ? 0 for no, 1 for yes'); if a == 0 end end

Answers (1)

Viren Gupta
Viren Gupta on 25 Sep 2018
Firstly you need to use 'strcmp' function in MATLAB rather than comparing the input strings using ==. '==' operator assumes same dimensions of its inputs. Hence you cannot compare 'rectangle' == 'cone'. Strcmp is used to compare strings in MATLAB. Also on the command prompt, enter as follows:-
Enter type of shape (enter cone for right circular cone, cylinder for cylinder,
rectangle for rectangular prism) : 'rectangle'
Donot just enter rectangle. Enter rectangle as a string.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!