Develop an algorithm for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 53840, and the user guesses 83241, the digits 3 and 4 are in the correct position. Thus, the program should respond with 2 and 7. Allow the user to guess a fixed number of times.
What will be an ideal response?
1. Generate a secret code
2. For guess is 1 to max
2.1. Get the users guess for the 5 digit code
2.2. Let correct be zero
2.3. Let sum be zero
2.4. For each digit
2.4.1. If the digit in the guess matches the users guess
2.4.1.1. Add 1 to correct
2.4.1.2. Add the value of the digit to sum
2.5. If correct is 5
2.5.1. Congratulate the user on guessing the code
2.5.2. Exit the program
2.6. Else
2.6.1. Display correct and sum
2.7. Ask if the user is making a deposit or withdrawal.
3. Display a message telling the user they did not guess the code within the maximum number of allowed guesses.
You might also like to view...
A predesigned set of colors, fonts, lines, and fill effects that look good together and which can be applied across all Office 2013 applications is called a:
A) design. B) style. C) theme. D) layout.
How often, at a minimum, should the disaster recovery plan be reviewed?
A) Weekly B) Monthly C) Annually D) Semiannually
If the following sentence is free of errors, choose the answer True. If there are errors in the sentence, choose the answer False and explain how to correct the sentence.As soon as you get your credit card statement, check is for errors.?
Answer the following statement true (T) or false (F)
Only functions defined where, in relation to the main function, require a function prototype to be coded?
A. above B. below C. within D. outside