loops and divisions by 7 and calling function
29 次查看(过去 30 天)
显示 更早的评论
function [whatsLeft, divisionCount] = divideBySeven(number) %Enter the code for your function here. while number < 1 number = number / 7 divisionCount = divisionCount + 1 end whatsLeft = number this is my code to call my function: [whatsLeft, divisionCount] = divideBySeven(256) I tried to run this and the error was that: Output argument "divisionCount" (and maybe others) not assigned during call to "divideBySeven".
0 个评论
采纳的回答
KSSV
2020-11-22
function [whatsLeft, divisionCount] = divideBySeven (number)
% Enter the code for your function here.
while number <1
number = number / 7
divisionCount = divisionCount + 1
end
whatsLeft = number
In the above you are using the variable divisonCountinside the loop and you have not defined it. You have to define it.
function [whatsLeft, divisionCount] = divideBySeven (number)
% Enter the code for your function here.
divisionCount = 0;
while number <1
number = number / 7
divisionCount = divisionCount + 1
end
whatsLeft = number
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!