lundi 12 juin 2017

Variable in If statement not recognized [duplicate]

This question already has an answer here:

So I'm trying to create a program that converts temperatures from Farenheit to Celsius and vice versa

  Scanner keyboard = new Scanner(System.in);

  int temperature;





  System.out.println("Enter a temperature.");
  temperature = keyboard.nextInt();
  System.out.println("Is the temperature in Celsius or Farenheit? For Farenheit enter F. For Celsius enter C.");
  char degrees = keyboard.next().charAt(0);
  double degrees_c, degrees_f;  

  if (degrees == 'F')
     degrees_c = 5 * (temperature - 32) / 9;
     System.out.printf (temperature + " degrees Farenheit is %.2f", degrees_c);
     System.out.println(" degrees Celsius."); 

Says that degrees_c is not initialized? How would I go about fixing this?

Aucun commentaire:

Enregistrer un commentaire