# Need help on this question

86 Ansichten (letzte 30 Tage)
Batuhan Yildiz am 29 Okt. 2022
Kommentiert: DGM am 13 Apr. 2024 um 9:44
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 (2)

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.

Janela Alex am 13 Apr. 2024 um 7:57
Diese(r) Antwort wurde durch DGM markiert
Code has already been provided to define a function named paceCalculator that accepts a single input variable marathonTime that expects a character array representing a runner's race time in hours:minutes:seconds format (HH:MM:SS).
Add commands to the function that uses the information in this character array to compute the average mile pace time in decimal minutes and assigns the result to the output variable milePace.
A marathon is miles long. For an example calculation, if the total time is , then the average mile pace, in units of minutes per mile would be calculated as:
Solve this problem using vectorized code. Your code should not include the following MATLAB functions or keywords: if, for, while. Note the variable marathonTime is defined as a function input. Do not overwrite the value in your code.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
DGM am 13 Apr. 2024 um 9:44
This is not an answer to this question. It's not an answer at all. It's also not a question.
You just copied and pasted a homework assignment without even bothering to look to see that half of it is missing.
If you want to ask a question, read this, and then ask a new question instead of hiding copypasta in random places on the internet.

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