Exercise 1 Write a program that asks the user to enter the seed for a random number generator. Then the program uses this seed to roll a dice and hence generates two integers corresponding to the faces of each dice. If their sum is odd, the user has two tries to guess the sum. The program gives the user a hint after the first try. Otherwise, the user has three tries to guess the sum.
Sample run 1: Enter the seed of the random number generator: 15
The sum is odd, you have two tries to guess the sum.
Enter first guess: 7 Incorrect. Hint: Sum is larger than 7.
Try again:
9 Incorrect.
The sum is 5+6 = 11
Sample run 2: Enter the seed of the random number generator: 52
The sum is even, you have three tries to guess the sum. Enter first guess: 6
Incorrect. Try again: 10
Incorrect. Try again: 8
Congratulations, sum of 5+3 is 8
PROGRAM:
import java.util.*;
public class calendar {
public static void main(String[] args) {
int
x=0,y=0,g=0,n,sum,c;
System.out.println("Enter the seed of the random number
generator:");
Scanner sc=new
Scanner(System.in);
n=sc.nextInt();
// Reading seed value from the user
Random rnd = new
Random(n);
x=rnd.nextInt(6)+1;
// generating first die face value
y=rnd.nextInt(6)+1;
// generating second die face value
sum=x+y;
if(sum%2==0)
// if the sum is even threee chances for guessing
{
c=3;
System.out.print("The Sum is even you have 3
tries to guess the sum\n ");
while(c>=0)
{
if(c==3)
{
System.out.println("Enter first guess:");
g=sc.nextInt();
if(g==sum)
{
System.out.println("congratulations,sum of
"+x+"+"+y+ " is "+sum);
break;
}
else
{
System.out.println("Incorrect.");
if(g>sum)
{
System.out.println("hint:sum
is less than "+g);
}
else
{
System.out.println("hint:sum
is greater than "+g);
}
}
}
else if(c==2)
{
System.out.print("Try again:");
g=sc.nextInt();
if(g==sum)
{
System.out.println("congratulations,sum of
"+x+"+"+y+ " is "+sum);
break;
}
else
{
System.out.print("Incorrect.");
}
}
else if(c==1)
{
System.out.print("Try again:");
g=sc.nextInt();
if(g==sum)
{
System.out.println("congratulations,sum of
"+x+"+"+y+ " is "+sum);
break;
}
else
{
System.out.print("Incorrect.");
}
}
else
if(c==0)
// if he/she failed in 3 chances then revealing the correct
answer
{
System.out.println("\nThe sum is "+x+"+"+y+"="+sum);
}
c--;
}
}
else // if the sum
is odd
{
c=2;
System.out.print("The Sum is odd you have 2
tries to guess the sum \n");
while(c>=0)
{
if(c==2)
{
System.out.println("Enter first guess:");
g=sc.nextInt();
if(g==sum)
{
System.out.println("congratulations,sum of
"+x+"+"+y+ " is "+sum);
break;
}
else
{
System.out.println("Incorrect");
if(g>sum)
{
System.out.println("hint:sum
is less than "+g);
}
else
{
System.out.println("hint:sum
is greater than "+g);
}
}
}
else if(c==1)
{
System.out.print("Try again:");
g=sc.nextInt();
if(g==sum)
{
System.out.println("congratulations,sum of
"+x+"+"+y+ " is "+sum);
break;
}
else
{
System.out.print("Incorrect");
}
}
else
if(c==0) // if he/she
failed in 2 chances then revealing the correct answer
{
System.out.println("\nThe sum is "+x+"+"+y+"="+sum);
}
c--;
}
System.out.println(x+" "+y);
}
}
}
OUTPUT:


Exercise 1 Write a program that asks the user to enter the seed for a random...
(c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...
Solve Question using While loops-MATLAB Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.
Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....
In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....
Write a program that calls the random number generator two times to simulate rolling a pair of dice. It should store the two numbers into variables. It will then determine if the dice roll is a winner (doubles OR add up to 7). Remember to add two includes and also to seed the random number generator to the clock. This will roll two dice and add them together. Doubles, or a total of 7 - YOU ARE A WINNER!!! First...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...
please explain!!! thanks!!
Write a C program that asks the user to guess your favorite Florida city. The user can't exceed 4 trials. Sample Run 1: Guess my favorite Florida city: Orlando No! Try again: MiAmi No! Try again: Fort meyers That's the one! Note that if the user could have entered FORT MEYERS. That is: FORT MEYERS, FORT MeyeRS, fort MEYERs.. are all the same. Search if there are some predefined function to use in this context Sample Run...
Write a program(JAVATPOINT) that generates a random number between 0 and 100 and asks the user to guess it. The user can have at maximum 10 trials. If the number is guessed, the user should be asked if she/he wants to play again. If the number is not guessed and 10 trials were used, the user is not lucky, the program should terminate with a proper message.
Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...