loops and divisions by 7 and calling function

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".

 Akzeptierte Antwort

KSSV
KSSV am 22 Nov. 2020

1 Stimme

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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

I W
am 22 Nov. 2020

Bearbeitet:

I W
am 17 Dez. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by