I've been sitting here (embarrassingly) for hours trying to get a do-while loop to to accept user input until it's valid, but I seem to be messing up when it comes to the boolean that I'm using to try and exit the loop. Whenever I can get the program to partially work the catch exception just ends up repeating itself infinitely.
Scanner scnr = new Scanner(System.in);
double wallHeight = 0.0;
boolean valid = false;
// Implement a do-while loop to ensure input is valid
// Prompt user to input wall's height
do {
try {
System.out.println("Enter wall height (feet): ");
wallHeight = scnr.nextDouble();
valid = false;
if (wallHeight <=0) {
throw new Exception ("Invalid Input");
}
}
catch (Exception e) {
System.out.println("Invalid Input");
}
} while (!valid);