Asked by jamar
A game program contains the following code to update three score variables, health, food, and knowledge. The maximum values for the three variables are 100, 80, and 25, respectively. health health + 10 IF(health > 100) { health 100 } food food + 1 IF(food > 80) { food 80 } knowledge knowledge + 5 IF(knowledge > 25) { knowledge 25 } The game program’s author would like to write a procedure that could be used to update any variable in the game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of the procedure is shown below. myScore updateScore(myScore, myAmount, myLimit) Which of the following is a correct implementation of updateScore ? PROCEDURE updateScore(score, amount, limit) { score score + amount IF (score > limit) { score limit } } Option A,PROCEDURE updateScore(score, amount, limit) { score ← score + amount IF (score > limit) { score ← limit } } A PROCEDURE updateScore(score, amount, limit) { score score + amount IF(score > amount) { score limit } RETURN(limit) } Option B,PROCEDURE updateScore(score, amount, limit) { score ← score + amount IF(score > amount) { score ← limit } RETURN(limit) } B PROCEDURE updateScore(score, amount, limit) { score score + amount IF(score > limit) { score limit } RETURN(score) } Option C,PROCEDURE updateScore(score, amount, limit) { score ← score + amount IF(score > limit) { score ← limit } RETURN(score) } C PROCEDURE updateScore(score, amount, limit) { IF(score = health) { score score + 10 } IF(score = food) { score score + 1 } IF(score = knowledge) { score score + 5 } IF(score > limit) { score limit } } Option D,PROCEDURE updateScore(score, amount, limit) { IF(score = health) { score ← score + 10 } IF(score = food) { score ← score + 1 } IF(score = knowledge) { score ← score + 5 } IF(score > limit) { score ← limit } } D
All Answers 1
Answered by
GPT-5 mini
AI
Correct answer: Option C.
Reason: It adds amount to score, caps it at limit when necessary, and returns the updated score. The other options are wrong because A doesn't return a value, B uses the wrong comparison and returns limit incorrectly, and D hard-codes checks for specific variables (not generic) and also doesn't return the result.
Reason: It adds amount to score, caps it at limit when necessary, and returns the updated score. The other options are wrong because A doesn't return a value, B uses the wrong comparison and returns limit incorrectly, and D hard-codes checks for specific variables (not generic) and also doesn't return the result.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.