Please any one can help me to fix my last statement of code I'm traying to have a user input the temp and then convert ot either F or C. But my last if else statement doesnot engage well with the over all code. I'm beginner Java programnig. Thank you in advanced.
import java.util.*;
public class CelsiusFahrenheit {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Would you like to convert from Fahrenheit to Celcius or Celcius to Fahrenheit?");
System.out.println("(1) Fahrenheit to Celcius");
System.out.println("(2) Celcius to Fahrenheit");
int choice = in.nextInt(); //Get user input on whether to do F to C or C to F
if (choice != 1 && choice != 2)
{
System.out.println("That was not one of the choices."); //handle if they don't enter a valid choice.
}
else if (choice == 1) //Fahrenheit to Celcius
{
System.out.println("Please enter the temperature in Fahrenheit to be converted to Celcius:");
double toConvertFahrenheit = in.nextDouble(); //Get user input for value to convert... Used double to support decimals
toConvertFahrenheit = (((toConvertFahrenheit-32)*5)/9); //subtract 32, multiply by 5, then divide by 9
System.out.println("Your converted value is: " + toConvertFahrenheit + " degrees Celcius.");
System.out.println("You Need to Wear a t-shirt");
}
else if (choice == 2)
{
System.out.println("Please enter the temperature in Fahrenheit to be converted to Celcius:");
double toConvertCelcius = in.nextDouble();
toConvertCelcius = (((toConvertCelcius*9)/5)+32); //multiply by 9, divide by 5, add 32.
System.out.println("Your converted value is: " + toConvertCelcius + " degrees Fahrenheit.");
// What to wear statement IS NOT WORKING.
if (toConvertFahrenheit <= 32) {
System.out.println("Your must wear a coat" + toConvertCelcius );
}
else if (toConvertCelcius >= && toConvertFahrenheit <= 211 ) {
System.out.println("Your need to wear t-shirt" + toConvertCelcius);
}
} // comment 1
} // comment 2
} // comment 3