Question: c++ program ex4.cpp : #include #include using namespace std; // ----- COPY FUNCTION generate() FROM EX3 HERE ----- // int main() { // 1. Define

c++ program ex4.cpp :

#include #include using namespace std;

// ----- COPY FUNCTION generate() FROM EX3 HERE ----- //

int main() { // 1. Define four integer variables (call them // a, b, c, d) for storing the hidden numbers. // Use function generate() to store in them the // hidden random digits.

// 2. Define four integer variables (call them // d1, d2, d3, 4) for storing the player's guess.

// 3. Repeat For Ever: // // A. Read the player's guess. // // B. Initialize and then increment the number // of Bulls in each of the following cases: // - if d1 equals a // - if d2 equals b // - if d3 equals c // - if d4 equals d // // // C. If the number of Bulls is 4, stop // the game and print "YOU WIN!". // // // D. Initialize and then increment the number of // Cows in each of the following cases: // - Check if d1 does not equal a, but equals // b or c or d. // - Check if d2 does not equal b, but equals // a or c or d. // - Do the same for d3 and d4. // (use && and ||) // // // E. Print the number of Cows and Bulls.

return 0; }c++ program ex4.cpp : #include #include using namespace std; // ----- COPYFUNCTION generate() FROM EX3 HERE ----- // int main() { // 1.

Download ex4.cpp and add your name and ID at the top of the file as a comment. Follow the steps provided as comments in ex4.cpp to implement the game GuessTheNumber. In this game, the computer hides a number and the player tries to guess it. Proceed as follows: 1. Generate four unique random digits (use function generate from Ex. 3). 2. Ask the user to enter four digits as a guess. 3. Count the number of Bs and Cs: a. A guessed digit is a B if it equals the corresponding digit in the hidden number. b. A guessed digit is a C if it does not equal the corresponding hidden digit but equals one of the other hidden digits. Example: Hidden Number: Player's Guess: 3 0 7 8 0 5 7 9 Response: 10 and 1 B Cs and the number of Bs. 4. Display the number of 5. If the number of Bs equals 4, the player wins. If not, repeat. Example Run for the hidden number 7408: Enter four digits: 2 4 6 8 Bs = 2 CS Enter four digits: 3 5 7 9 Bs = 0 Cs = 1 Enter four digits: 4 8 YOU WIN! Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!