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
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
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
SACHIN KHANDELWAL 2024 年 6 月 26 日
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 ExchangeHypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by