Question

In: Computer Science

This is done in C++. This is a game where one player thinks of a number...

This is done in C++.

This is a game where one player thinks of a number between 1 and a 1000 and the other player has to guess in 10 tries or less.

Allow two variations: the computer to pick the number and the player guesses or the player to pick the number and the computer to guesses.

1 – Player one picks a number

2 – Player two guesses the number.

3 – Player one either confirms that the guess is correct or tells whether the guess is too high or too low.

4 – Steps 2 and 3 are repeated until count of 10 or the number is guessed correctly.

Notice that you are writing a binary search as you are searching natural numbers from1 to 1000. You may want to make it 1024 since 210 = 1024. This is a sorted array.

Solutions

Expert Solution

C++. game where one player thinks of a number between 1 and a 1000 and the other player has to guess in 10 tries or less.

CODE:

#include <iostream> //included to allow for cout/cin to be used

#include <cstdlib> //include to allow rand() and srand() to be used

#include <time.h>

using namespace std;

int main()

{

bool cont=true;

while(cont)

{

int count=0; // variable count to track number of guesses

int guess;

srand(time(0)); //seeds random number generator.

int x = rand() % 1000;

cout << "Guess a number between 1 -1000.You have only 10 tries\n"; // prompt user to guess a number

std::cin >> guess;

while (guess !=x && count <= 10) // check whether guess is equal or not and count is less than 10

{

if (guess > x)

{

cout << "Too high! Try again. "<<endl;

cin >> guess;

count++;

}

if (guess < x)

{

cout << "Too low! Try again. "<<endl;

cin>>guess;

count++;

}

if (guess == x)

{

cout << "\n\nYou' guessed it right. Good job! "<<endl;

return 0;

}

if (count==10)

{

cout << "\n\nYou're out of guesses!\n";

cout << "\nThe number was - "<<x;

return 0;

}   

}

}

return 0;

}


Related Solutions

) Consider a game where player 1’s possible three strategies are a, b and c and...
) Consider a game where player 1’s possible three strategies are a, b and c and player 2’s possible strategies are A, B and C. The players choose their strategies simultaneously. The payoff matrix of the game is as follows:                                           Player 2 A B C    a 8,5 9,7 10,8 player 1 b 6,1 10,3 7,9 c 5,4 8,6 6,4 (5 pts) Is there a dominated strategy for player 1? For player 2? Justify your answer. (5 pts) Is...
A carnival game offers a $100 cash prize for a game where the player tries to...
A carnival game offers a $100 cash prize for a game where the player tries to toss a ring onto one of many pegs. Alex will play the ring toss game five times, with an 8% chance of making any given throw. What is the probability that Alex tosses one of the five rings onto a peg? What is the probability that Alex tosses more than one of the five rings onto a peg? If Alex tossed five rings again...
In the game of​ roulette, a player can place a ​$ 4 bet on the number...
In the game of​ roulette, a player can place a ​$ 4 bet on the number 27 and have a StartFraction 1 Over 38 EndFraction 1 38 probability of winning. If the metal ball lands on 27​, the player gets to keep the ​$ 4 paid to play the game and the player is awarded an additional ​$ 140 . ​ Otherwise, the player is awarded nothing and the casino takes the​ player's ​$ 4 . What is the expected...
Consider a game in which, simultaneously, player 1 selects any real number x and player 2...
Consider a game in which, simultaneously, player 1 selects any real number x and player 2 selects any real number y. The payoffs are given by: u1 (x, y) = 2x − x2 + 2xy u2 (x, y) = 10y − 2xy − y2. (a) Calculate and graph each player’s best-response function as a function of the opposing player’s pure strategy. (b) Find and report the Nash equilibria of the game. (c) Determine the rationalizable strategy profiles for this game.
In the game of​ roulette, a player can place a ​$4 bet on the number 14...
In the game of​ roulette, a player can place a ​$4 bet on the number 14 and have a StartFraction 1 Over 38 EndFraction probability of winning. If the metal ball lands on 14​, the player gets to keep the ​$4 paid to play the game and the player is awarded an additional ​$140. ​ Otherwise, the player is awarded nothing and the casino takes the​ player's ​$4. What is the expected value of the game to the​ player? If...
In the game of​ roulette, a player can place a ​$9 bet on the number 6...
In the game of​ roulette, a player can place a ​$9 bet on the number 6 and have a 1 /38 probability of winning. If the metal ball lands on 6​, the player gets to keep the ​$9 paid to play the game and the player is awarded an additional ​$315 ​Otherwise, the player is awarded nothing and the casino takes the​ player's ​$9. Find the expected value​ E(x) to the player for one play of the game. If x...
Provide an example of a 2-player normal form game where each player has 3 (pure) strategies...
Provide an example of a 2-player normal form game where each player has 3 (pure) strategies such that: (i) There is exactly one pure strategy Nash equilibrium. (ii) There are exactly two pure strategy Nash equilibria. (iii) There are exactly three pure strategy Nash equilibria. (iv) There are exactly nine pure strategy Nash equilibria
5. (Games w/o conflict) Give an example of a two player strategic game where each player...
5. (Games w/o conflict) Give an example of a two player strategic game where each player has two actions and have identical preferences over outcomes, so that there is no conflict between their interests. a. Represent the game in normal form (bimatrix). b. Support with link to news article, pictures, or similar.
In a carnival game, a player spins a wheel that stops with the pointer on one...
In a carnival game, a player spins a wheel that stops with the pointer on one (and only one) of three colors. The likelihood of the pointer landing on each color is as follows: 62 percent BLUE, 24 percent RED, and 14 percent GREEN. Note: Your answers should be rounded to three decimal places. (a) Suppose we spin the wheel, observe the color that the pointer stops on, and repeat the process until the pointer stops on BLUE. What is...
In a carnival game, a player spins a wheel that stops with the pointer on one...
In a carnival game, a player spins a wheel that stops with the pointer on one (and only one) of three colors. The likelihood of the pointer landing on each color is as follows: 64 percent BLUE, 22 percent RED, and 14 percent GREEN. Note: Your answers should be rounded to three decimal places. (a) Suppose we spin the wheel, observe the color that the pointer stops on, and repeat the process until the pointer stops on BLUE. What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT