Question

In: Computer Science

Write a program where a user of this program will play a game in which he/she...

Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.

Solutions

Expert Solution

// This is a comment: You did not mention a specific language so I created a simple on C programming language

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int smallInteger,largeInteger,guessInteger;
printf("Enter a number : ");
scanf("%d", &smallInteger);
printf("Enter a Larger number than before : ");

//loop to get input form the user and some error checking
scanf("%d", &largeInteger);
while( smallInteger > largeInteger){
printf("Please make sure the second number is neither smaller nor the same as the first number \n");
printf("Enter a Larger number than before : ");
scanf("%d", &largeInteger);
}

srand(time(0)); //Using time as an random seed for our rand() function
int originalInteger = (rand() % (largeInteger - smallInteger + 1)) + smallInteger; // Bringing the range to our desired reange

//loop to compare the user input number to the actual number
while(guessInteger!=originalInteger && guessInteger!="exit"){
printf("Alright, it's time to guess now. What do you think it is? : \n");
scanf("%d", &guessInteger);
if(guessInteger != originalInteger ){
if(guessInteger < smallInteger || guessInteger > largeInteger){
printf("Oops, you seem to have forgotten your range. It is between %d and %d \n", smallInteger, largeInteger );
}
if(guessInteger < originalInteger ){
printf("Nope. Try again! Here is a hint : It is larger than you expected \n");
}
if(guessInteger > originalInteger){
printf("Nope. Try again! Here is a hint : It is smaller than you expected \n");
}
}else if( guessInteger == originalInteger){
printf ("OH, WINNER WINNER CHICKEN DINNER");
break;
}
}
return 0;
}

SAMPLE OUTPUT


Related Solutions

Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
Write a program to allow a user to play the game Hangman. DO NOT USE AN...
Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess. Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the...
Write a program in Matlab where the program plays a hot and cold game. The user...
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play...
Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play the game of rock, paper, scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen...
Write a program in Basic to play the game of Nim with acom­puter.
Write a program in Basic to play the game of Nim with acom­puter.
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack,...
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack, which is played between the user and an automated dealer as follows. The dealer shuffles a standard deck of 52 cards, draws two cards, and gives them to the user. The user can then choose to request another card from the dealer, adding it to their hand. The user can continue to request cards or choose to stop at any time. After each time...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
Lily likes to play games with integers. She has created a new game where she determines...
Lily likes to play games with integers. She has created a new game where she determines the difference between a number and its reverse. For instance, given the number 12, its reverse is 21. Their difference is 9. The number 120 reversed is 21, and their difference is 99. She decides to apply her game to decision making. She will look at a numbered range of days and will only go to a movie on a beautiful day. Given a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT