I can't figure out why the last line of my code is throwing the error "cont cannot be resolved to a variable" Basically I need to covert Fahrenheit to celsius in a loop in case they want to convert more than one temperature.
I also need to have the program ask them to re enter the temperature type if they say something other than c or f without asking them to re enter the number
Those are my two problems and heres my code thanks!
//Jonathan Towell
//This program will convert temperatures from celsius to Fahrenheit
import javax.swing.JOptionPane;
public class FarenheitOrCelsius
{
public static void main(String[] args)
{
do
{
double temp = Double.parseDouble(JOptionPane.showInputDialog("Enter the temperature to be converted"));
String ver = JOptionPane.showInputDialog("Is that temperature in celsius or fahreneheit?\n" + "Enter C or F");
if (ver.toLowerCase().contains("c")) //If C is entered convert to fahrenheit
{
double result = Math.round(((9 * (temp)/5) + 32));
JOptionPane.showMessageDialog(null, "You entered " + temp + " degrees celsius.\n" + "That temperature in fahrenheit is " + result);
int cont = Integer.parseInt(JOptionPane.showInputDialog("Do you want to convert another temperature?", JOptionPane.YES_NO_OPTION));
}
else if (ver.toLowerCase().contains("f")) //If f is entered covert to celsius
{
double result = Math.round((5 *(temp - 32)/9)); //Math equation for coversion from F to C
JOptionPane.showMessageDialog(null, "You entered " + temp + " degrees fahrenheit.\n" + "That temperature in celsius is " + result);
int cont = Integer.parseInt(JOptionPane.showInputDialog("Do you want to convert another temperatuer?", JOptionPane.YES_NO_OPTION));
}
else JOptionPane.showMessageDialog(null, "Invalid Option.\n Only enter C or F.");
{
System.exit(0);
}
} while (cont = JOptionPane.YES_OPTION);
}
}