Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Flow in C++ Get the number of digits for the code. Only accept inputs of 0, 3, 4, or 5. (Note: 0 is a

Program Flow in C++

Get the number of digits for the code.

Only accept inputs of 0, 3, 4, or 5. (Note: 0 is a cheat code)

Repeat until a valid choice is input.

Load vector with code digits

If 0 is input as number of digits for the code: (Note: This will allow TAs/autograding to enter a code to make testing easier. Since this is for testing purposes, you do not have to check these for correct input.)

Get code as a single integer (int).

Get the number of digits for the code. (Note: You need this so you can add a leading zero if needed, e.g. they type in 29 and you need to create 029.)

Extract individual digits from the single integer and put into the vector for the code. Consider using integer division and modulus.

Else randomly create a valid code. (i.e. number of digits was 3, 4 or 5)

Load vector with the appropriate number of random digits ensuring there are no duplicates.

Regardless of the method you used to create the code (entered from keyboard or randomly generated), output the code to be guessed. (This is purely to help with auto-grading. Of course in a published game you would not output the code.)

Note: Be sure to match the output of the sample runs.

Coding Requirements:

The code and guess must each be stored in a vector of ints.

Follow formatting as demonstrated in the "Sample Runs" below.

. . . . . . . . . .

Sample Runs

This is not complete testing!

Enter number of digits in code (3, 4 or 5): 0 Enter code: 2894 Enter number of digits in code: 4 Number to guess: 2894 Enter number of digits in code (3, 4 or 5): 0 Enter code: 29 Enter number of digits in code: 3 Number to guess: 029 Enter number of digits in code (3, 4 or 5): 5 Number to guess: 48502

Enter number of digits in code (3, 4 or 5): 3 Number to guess: 072

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions