I'm a fresher here who has just finished the matlab onramp course but unable is stuck at the practise problem.
8 views (last 30 days)
Show older comments
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 Comments
Steven Lord
on 10 Jun 2024
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
on 17 Jun 2024
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
Accepted Answer
SACHIN KHANDELWAL
on 26 Jun 2024
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!
More Answers (0)
See Also
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!