Make sure that when a user makes a correct guess all

This preview shows page 73 - 76 out of 77 pages.

---. Make sure that when a user makes a correct guess, all the matching letters arefilled in. For example, if the word isbananaand the user guessesa, all threeacharacters should be filled in.Answer:A sample solution followsPseudocode:startDeclarationsnum xnum numCorrectnum LENGTH = 8string WORD[LENGTH] = “C”, “O”, “M”, “P”, “U”,“T”, “E”, “R”string hiddenWord[LENGTH] = “-”,“-”,“-”,“-”,“-”,“-”,“-”,“-”string guessgetReady()while numCorrect not equal to LENGTHdetailLoop()endwhilefinishUp()stopgetReady()numCorrect = 0output hiddenWordoutput “Please guess a letter”input guessreturndetailLoop()x = 0while x < LENGTHif WORD[x] = guess thennumCorrect = numCorrect + 1hiddenWord[x] = guess73
We have textbook solutions for you!
/Programming-Logic-and-Design-Introductory-9th-Edition-9781337109635-772/
The document you are viewing contains questions related to this textbook.
Chapter 6 / Exercise 19
Programming Logic and Design, Introductory
Farrell
Expert Verified
Programming Logic and Design, 8eSolutions 6-endifx = x + 1endwhileoutput hiddenWordif numCorrect not equal to LENGTHoutput “Please guess a letter”input guessendifreturnfinishUp()output “You guessed the word!”output hiddenWordreturn5.Create two parallel arrays that represent a standard deck of 52 playing cards. Onearray is numeric and holds the values 1 through 13 (representing Ace, 2 through 10,Jack, Queen, and King). The other array is a string array that holds suits (Clubs,Diamonds, Hearts, and Spades). Create the arrays so that all 52 cards are represented.Then, create a War card game that randomly selects two cards (one for the player andone for the computer) and declares a winner or a tie based on the numeric value of thetwo cards. The game should last for 26 rounds and use a full deck with no repeatedcards. For this game, assume that the lowest card is the Ace. Display the values of theplayer’s and computer’s cards, compare their values, and determine the winner. Whenall the cards in the deck are exhausted, display a count of the number of times theplayer wins, the number of times the computer wins, and the number of ties.Here are some hints:Start by creating an array of all 52 playing cards.Select a random number for the deck position of the player’s first card and assignthe card at that array position to the player.Move every higher-positioned card in the deck “down” one to fill in the gap. Inother words, if the player’s first random number is 49, select the card at position49 (both the numeric value and the string), move the card that was in position 50to position 49, and move the card that was in position 51 to position 50. Only 51cards remain in the deck after the player’s first card is dealt, so the available cardarray is smaller by one.In the same way, randomly select a card for the computer and “remove” the cardfrom the deck.Answer:A sample solution followsPseudocode:startDeclarationsnum xnum y74
Programming Logic and Design, 8eSolutions 6-num limitnum indexnum playerCardnum playerCardNumnum computerCardnum computerCardNumnum playerWin = 0num computerWin = 0num tie = 0string playerCardSuitstring computerCardSuitnum LENGTH = 52num GROUPS = 4num ROUNDS = 26num BOUNDS[GROUPS] = 0, 13, 26, 39num cards[LENGTH] =1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 77 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
NUM, sentinel value
We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Programming Logic and Design, Introductory
The document you are viewing contains questions related to this textbook.
Chapter 6 / Exercise 19
Programming Logic and Design, Introductory
Farrell
Expert Verified

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture