loops and divisions by 7 and calling function

조회 수: 7 (최근 30일)
I W
I W 2020년 11월 22일
편집: I W 2021년 12월 17일
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".

채택된 답변

KSSV
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by