필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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

답변 (1개)

Viren Gupta
Viren Gupta 2018년 9월 25일
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.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by