Ok im trying to make a lil random number game. I have most of the code and comments on how i want the game to work. but i can not get to it work. if you have any answers any help what so ever it woul be greatly appreciated!
[code=java]
package mooredMod2;
import java.util.Scann er;
import java.util.Rando m;
public class GuessingGame {
public static void main(String[] args) {
Scanner scan = new Scanner(System. in);
// declare a boolean variable named more and set it equal to true
boolean more = true;
Random generator = new Random();
while (true)
{
// declare an integer variable named numGuesses and
// set it equal to zero
int numGuesses = 0;
// declare a boolean name correct and set it equal to false
boolean correct = false;
// declare an integer variable named theirGuess
int theirGuess;
// generate a number between one and ten and store it in a
// integer variable named value (see p126)
int value;
value = generator.nextI nt(10) + 1;
System.out.prin tln ( + value );
// print out the computer's value (for debugging purposes only) -
// you would remove this before
// really running the program but leave it in when you
// turn your project in
System.out.prin tln("Guess a number between 1 and 10");
// read their input from the keyboard using the Scanner
// class and store it in the variable theirGuess
theirGuess = scan.nextInt ();
while (value <= 0 ) // a loop from chapter 5
{
// increment the numGuesses variable
numGuesses = value + 1;
if(theirGuess<v alue)
{
System.out.prin tln("Too low!");
}
else if (theirGuess>val ue)
{
System.out.prin tln("Too high!");
}
//print out that they were correct and
}
// tell them how many guesses it took
// set the variable correct to true
// ask them if they want to play again - // let them know they need to answer true or false
// read their input from the keyboard using the
// Scanner class and store their answer in the variable named more
scan.nextInt ();
}
}//end of main method
}[/code]
Thanks
[code=java]
package mooredMod2;
import java.util.Scann er;
import java.util.Rando m;
public class GuessingGame {
public static void main(String[] args) {
Scanner scan = new Scanner(System. in);
// declare a boolean variable named more and set it equal to true
boolean more = true;
Random generator = new Random();
while (true)
{
// declare an integer variable named numGuesses and
// set it equal to zero
int numGuesses = 0;
// declare a boolean name correct and set it equal to false
boolean correct = false;
// declare an integer variable named theirGuess
int theirGuess;
// generate a number between one and ten and store it in a
// integer variable named value (see p126)
int value;
value = generator.nextI nt(10) + 1;
System.out.prin tln ( + value );
// print out the computer's value (for debugging purposes only) -
// you would remove this before
// really running the program but leave it in when you
// turn your project in
System.out.prin tln("Guess a number between 1 and 10");
// read their input from the keyboard using the Scanner
// class and store it in the variable theirGuess
theirGuess = scan.nextInt ();
while (value <= 0 ) // a loop from chapter 5
{
// increment the numGuesses variable
numGuesses = value + 1;
if(theirGuess<v alue)
{
System.out.prin tln("Too low!");
}
else if (theirGuess>val ue)
{
System.out.prin tln("Too high!");
}
//print out that they were correct and
}
// tell them how many guesses it took
// set the variable correct to true
// ask them if they want to play again - // let them know they need to answer true or false
// read their input from the keyboard using the
// Scanner class and store their answer in the variable named more
scan.nextInt ();
}
}//end of main method
}[/code]
Thanks
Comment