Hello, I am making a BMI calculator that is pretty much complete but I am currently stuck on an issue with a boolean, here is my code :
The problem is that I declared 2 booleans in the beginning to be false, but eclipse is telling me that the value of the local variable is not being used even though I have used them in the if statements to change the values depending on the user input. But as eclipse says, they are not being used so when I enter 2 for imperial, my code is treating it as if I pressed 1 for metric. How do I fix this issue with the boolean? thanks in advance !!!!import java.util.Scanner; public class BMI { public static void main(String[] args) { int choice; double weightKG; double weightLB; double heightM; double heightIN; double BMI; String name; boolean metric = false; boolean imperial = false; Scanner kb = new Scanner(System.in); System.out.println("Welcome to the Body Mass Index Calculator!\nPlease enter your name:"); name = kb.next(); System.out.println("Hello " + name +"! Please select a method to calculate your BMI. \n"); System.out.println("\nPress 1 for metric\nPress 2 for imperial\nPress 3 to exit"); choice = kb.nextInt(); if (choice == 1) { metric = true; imperial = false; } if (choice == 2) { imperial = true; metric = false; } if (choice == 3) { System.out.println("Exiting Program"); System.exit(0); } if (metric = true) { System.out.println("Please enter your weight in kilograms"); weightKG = kb.nextDouble(); System.out.println("Please enter your height in meters"); heightM = kb.nextDouble(); BMI = (weightKG/((heightM)*(heightM))); System.out.println(name + " your BMI is: "+ BMI); if (BMI < 18.5) { System.out.println(name + ", it seems you are a bit underweight"); } if (BMI >= 18.5 && BMI <= 25) { System.out.println(name + ", you have a normal weight"); } if (BMI >= 25 && BMI <= 30) { System.out.println(name + ", it seems you are overweight"); } if (BMI >= 30) { System.out.println(name + ", it seems you are obese"); } } if (imperial = true) { System.out.println("Please enter your weight in pounds"); weightLB = kb.nextDouble(); System.out.println("Please enter your height in inches"); heightIN = kb.nextDouble(); BMI = ((weightLB)/((heightIN)*(heightIN)))*703; System.out.println(name + " your BMI is: "+ BMI); if (BMI < 18.5) { System.out.println(name + ", it seems you are a bit underweight"); } if (BMI >= 18.5 && BMI <= 25) { System.out.println(name + ", you have a normal weight"); } if (BMI >= 25 && BMI <= 30) { System.out.println(name + ", it seems you are overweight"); } if (BMI >= 30) { System.out.println(name + ", it seems you are obese"); } } } }