186k views
3 votes
Consider the playGame procedure below which calls on 3 other procedures: countFives, player1Move, and player2Move.

PROCEDURE playGame()

{

cards = []

REPEAT_UNTIL ( countFives(cards) >= 5 )

{

card1 = player1Move()

APPEND (cards, card1)

card2 = player2Move()

APPEND (cards, card2)

}

}

The procedure above simulates a certain card game called "fives" - played with two decks of cards - in which each player takes a turn playing a card, until 5 fives have been played in total, at which point it's "Game Over." The procedure uses a list called cards which is initially empty. Each round of play, two cards are appended to the list.

Here is the countFives procedure.



PROCEDURE countFives(cards)

{

count = 0

FOR EACH card IN cards

{

IF( card = 5 )

{

count = count+1

}

}



}

Which of the following should replace the at line 12 to make the procedure work as designed?

A. DISPLAY (count)

B. DISPLAY ("game over")

C. RETURN (count)

D. RETURN ("game over")

E. Nothing. Procedure works as is.

1 Answer

4 votes

Answer:

c. RETURN (count)

Step-by-step explanation:

A typical return statement performs the function of terminating the execution of a function and returns control to the calling function.

Hence, there will execution resumed in the calling function at the point immediately following the call.

Another thing a return statement can do is to also return a value to the calling function.

The code RETURN (count) will

terminating the execution of a function and returns control to the calling function.

User Jmagder
by
6.1k points