vendredi 22 septembre 2017

How to get method to recognize else part of if statement?

I've made a street craps game and have an error checker in the beginning to make sure the input is valid, I put it in an if statement and then have the rest of the code (for valid inputs) as the else but it isn't recognizing the else part when the user puts in a valid number.

public void play(){ //method
System.out.println("Please pick a number.");
guess = scan.nextInt();
if (guess == 7 || guess == 1 || guess == 0 || guess > 12){
    System.out.println("Sorry, that is an invalid input, please choose another number.");
    guess = scan.nextInt();
} else{
int roll = dieOne.roll();
int roll2 = dieTwo.roll();
int rollSums = roll + roll2;
System.out.println(roll + "+" + roll2);
while (rollSums != 7){
  if (guess == rollSums){
    System.out.println("Congratulations, you win! Your number was rolled before a seven was rolled!");
    rollSums = 7;
    guess = 7;
  }
  else{
    roll = dieOne.roll();
    roll2 = dieTwo.roll();
    rollSums = roll + roll2;
    System.out.println(roll + "+" + roll2);
  }
}
  if (rollSums != guess){
   System.out.println("Sorry, your number was not rolled before a seven was rolled.");
}
}
}

Aucun commentaire:

Enregistrer un commentaire