I'm a fresher here who has just finished the matlab onramp course but unable is stuck at the practise problem.
조회 수: 8 (최근 30일)
이전 댓글 표시
Question:Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).And this is my answer:
function SA = func_frosting(r, h)
SA = (pi * r * r) + (2 * pi * r * h);
end
radius = 5;
height = 10;
surfaceArea = func_frosting(radius, height);
disp(['The surface area of the cake is ', num2str(surfaceArea), ]);
But it just passes one of the four code test.Please help.
댓글 수: 3
Steven Lord
2024년 6월 10일
Are you trying to solve Cody problem 44943? If so Cody should have showed you a message about which of its tests your code failed to satisfy. That information would be useful in offering suggestions for how to modify your code so it passes Cody's tests.
Venkatesha AT
2024년 6월 17일
What you have entered in first 3 lines is enough to solve all the 4 tests. Remove the extra lines.
function SA = func_frosting(r,h)
SA = (pi*r^2) + (2*pi*r*h);
end
채택된 답변
SACHIN KHANDELWAL
2024년 6월 26일
Hi @Divya
I've tried solving the same Cody problem that you're working on, and it works perfectly on my end. Here's the MATLAB code that's working for me:
function SA = func_frosting(r,h)
SA = pi*r*r + 2*pi*r*h;
end
The test cases are failing because there's extra, unnecessary code inside your solution. The test function checks the output of the "func_frosting" function. It compares what we expect the function to return (expected output) with what it actually returns (actual output).
Hope this is helpful!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!