# Need help on this question

8 Ansichten (letzte 30 Tage)
Batuhan Yildiz am 29 Okt. 2022
Kommentiert: Batuhan Yildiz am 29 Okt. 2022
Code has been provided to define a function named numberChecker that accepts a single input variable named RandomNumber. Add commands to check if the value is between 0 and 10 (consider values of exactly 0 and exactly 10 to be in range). If the value is in this range, assign the value 'The number is in range.' to the output character vector CheckRange. If the value is not in this range, assign the value 'The number is out of range.' to the output character vector CheckRange.
Use an if-else structure in your solution.
Note the variable RandomNumber is defined as an input to the function. Do not overwrite its value in your code.
My Code so far:
function CheckRange = numberChecker(RandomNumber)
% TO-DO: on line 5 add the following, right beside the word "if"
% check that input argument variable for numberChecker is
% between 0 and 10 (including both 0 and 10).
if(RandomNumber>=0 & RandomNumber<=10)
% TO-DO: make the character array below say The number is in range.
CheckRange = 'The number is in range';
else
% TO-DO: make the character array below say The number is out of range.
CheckRange = 'The number is out of range';
end
RandomNumberIn = 1 + 15*rand(1,1) %creates random number to test function
CheckRangeOut = numberChecker(RandomNumberIn)
What's wrong about the code that I don't know how to fix:
Assessment: 1 of 4 Tests Passed
What I got wrong:
• Assessment result: incorrect Does code correctly identify a number that is in range? Variable CheckRange has an incorrect value.Double check spelling and capitalization to ensure the output text is exactly as specified in the problem statement.
• Assessment result: incorrect Does code correctly identify a number that is out of range? Variable CheckRange has an incorrect value.Double check spelling and capitalization to ensure the output text is exactly as specified in the problem statement. Make sure your function will work correctly for negative input values.
• Assessment result: incorrect Does code correctly identify a number that is on the upper or lower boundary of the range? Variable CheckRange0 has an incorrect value. Be sure you have used the correct relational operators to define the range as including the upper and lower boundaries.
##### 2 KommentareKeine anzeigenKeine ausblenden
Walter Roberson am 29 Okt. 2022
RandomNumberIn = 1 + 15*rand(1,1) %creates random number to test function
CheckRangeOut = numberChecker(RandomNumberIn)
Those two lines do not belong inside of the function.
If you remove them then the code appears to work when I test
Batuhan Yildiz am 29 Okt. 2022
Please take a look at these screen shots

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Steven Lord am 29 Okt. 2022
Look very closely at the character vectors you're supposed to assign to the variable. You're missing the periods at the end of the character vectors you assign in your code.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by