Receiving a syntax error on my curly braces but no matter how many I close it still gives an error. Can't figure it out. Thank you for any advice on this I am at a loss. I have tried adding more and removing more. I had the count of how many I needed to close but still getting an error.
import java.util.Scanner;
public class Paint1 {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double wallHeight = 0.0;
double wallWidth = 0.0;
double wallArea = 0.0;
double gallonsPaintNeeded = 0.0;
final double squareFeetPerGallons = 350.0;
// Implement a do-while loop to ensure input is valid
// Prompt user to input wall's height
do {
System.out.println("Enter wall height (feet): ");
wallHeight = scnr.nextDouble();
while (!scnr.hasNextInt()) {
System.out.printf("\"%s\" is not a valid number.\n");
System.out.println("Please enter wall height in feet: ");
} while (wallHeight < 0) {
// Implement a do-while loop to ensure input is valid
// Prompt user to input wall's width
do {
System.out.println("Enter wall width (feet): ");
wallWidth = scnr.nextDouble(); // changed wallHeight to wallWidth
while (!scnr.hasNextDouble()) {
System.out.printf("\"%s\" is not a valid number.\n");
System.out.println("Please enter wall width in feet: ");
} while (wallWidth < 0) {
// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.println("Wall area: " + wallArea + " square feet"); // added variable
// Calculate and output the amount of paint (in gallons) needed to paint the wall
gallonsPaintNeeded = wallArea/squareFeetPerGallons;
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons"); // changed variable to correct case
}
}
You seem to have an extra curly brace in the
} while (wallWidth < 0) {
line. Have you tried removing that? The opening brace is fine, but the one at the end of the line might be giving you issues.