java help for converting temperture

I think you are missing curly brackets around your if/else statements

    if (ConvertFer == 0) {
      // convert to F

    }
    else { 
     // convert to C
    } 

Also, you should read user choice before the if/else statements. You might also want to loop your code so you can do this conversion multiple times

public static void main(String[] args) {
   Scanner reader = new Scanner(System.in);

   double F = 0;
   double C = 0;
   int ConvertFer = 0;
   int ConvertCel = 1;
   int Done = 3;
   System.out.println("Welcome to the Temperature Converter!\n" +
                        "Enter 0 to convert F --> C and 1 to convert from C --> F.\n" +
                        "Enter 3 when done");

  int userChoice = -1;
  while(true) {
      userChoice = reader.nextInt();  // read user choice
      if(userChoice == ConvertFer) {
          // convert to F
      } else if(userChoice == ConvertCel) {
          // convert to C
      } else if (userChoice == Done) {
          break; // finish the loop
      } else {
          System.out.println("Please enter a valid choice");
      }
  }
} 

Note You also shouldn’t capitalize your variables by convention so they can be easily differentiated from classes. You should rename your variables to convertFer, convertCel and done

Leave a Comment