Ask Question

In the Guess My Number program, the user continues guessing numbers until the secret number is matched. Assuming numGuesses is initialized to 1, how would the while statement be modified to include an extra criterion limiting the number of guesses to 15?

A) while ((userGuess = = secretNumber) || numGuesses < 14)

B) while ((userGuess= = secretNumber) && numGuesses < = 15)

C) while (! (userGuess = = secretNumber) || numGuesses < 15)

D) while (! (userGuess = = secretNumber) && numGuesses < 15)

E) while (! (userGuess = = secretNumber) && numGuesses < = 15)

+1
Answers (1)
  1. 28 February, 21:09
    0
    E) while (! (userGuess = = secretNumber) && numGuesses < = 15)

    Explanation:

    The first part of this answer! (userGuess = = secretNumber) verifies that the userGuess is not equal to the secretNumber. Yes, the equal sign (double as it should be when comparing things) is between the userGuess and the secretNumber, but all this expression is inside a parenthesis ... which is negated by the! before it.

    The second part verifies tht the numGuesses < = 15 because the counter is initialized at 1, so to get a total of 15 values, we have to go from 1 to 15. If it had been initialized at 0, we would have checked for 14.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “In the Guess My Number program, the user continues guessing numbers until the secret number is matched. Assuming numGuesses is initialized ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers