I just want to know how to remove that initialized wgt error. Rest, I want my code to be basic and very simple.
//Program By Aryansh Malviya
//BMI Calculator
import java.util.Scanner;
public class BMICalc
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int cw;
int ch;
int bmi;
int wgt;
int hgt;
int ct;
System.out.print("\nNote: This program is not yet fully functional.\nThere might be issues regarding decimal values. \nProgram has not been equipped to accept or display in decimal values. \nThe program will be updated soon. \nSorry for the inconvinience.");
System.out.print("Enter 1 if you want weight in Kilograms");
System.out.print("Enter 2 if you want weight in Pounds");
cw = input.nextInt();
System.out.print("\nNote: If you choose to enter weight in Pounds, you'd have to enter height in Inches. Else, in meters");
if(cw == 1)
{
System.out.print("\nEnter weight in Kilograms: ");
wgt = input.nextInt();
}
else if(cw == 2)
{
System.out.print("\nEnter weight in Pounds: ");
wgt = input.nextInt();
}
else
{
System.out.print("\nEnter a valid choice and try again!");
}
System.out.print("\nEnter your height: ");
hgt = input.nextInt();
bmi = wgt/(hgt * hgt);
System.out.printf("\nYour weight is: %d", wgt);
System.out.printf("\nYour height is: %d", hgt);
System.out.printf("\n\nYour BMI is: %d", bmi);
System.out.print("\nBMI VALUES");
System.out.print("\nUnderweight: less than 18.5");
System.out.print("\nNormal: between 18.5 and 24.9");
System.out.print("\nOverweight: between 25 and 29.9");
System.out.print("\nObese: 30 or greater");
}
}
When I compile the program I get the error that the variable wgt has not been initialized. Please tell me how to solve this problem.