I'm a fresher here who has just finished the matlab onramp course but unable is stuck at the practise problem.

9 visualizzazioni (ultimi 30 giorni)
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 Commenti
Steven Lord
Steven Lord il 10 Giu 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
Venkatesha AT il 17 Giu 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

Accedi per commentare.

Risposta accettata

SACHIN KHANDELWAL
SACHIN KHANDELWAL il 26 Giu 2024
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!

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by