I'm a fresher here who has just finished the matlab onramp course but unable is stuck at the practise problem.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Divya
el 10 de Jun. de 2024
Comentada: Divya
el 27 de Jun. de 2024
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 comentarios
Steven Lord
el 10 de Jun. de 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
el 17 de Jun. de 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
Respuesta aceptada
SACHIN KHANDELWAL
el 26 de Jun. de 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!
Más respuestas (0)
Ver también
Categorías
Más información sobre Hypothesis Tests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!