I'm having trouble resolving how to take an input based of two possible options and returning a value for both options.
example:
What temperature system do you use: celsius or Fahrenheit
(after selection is made, in this case celsius, take answer and convert to Fahrenheit)
Output both temperatures
I've tried 'if else' and 'switch' statement but the when I make a selection say Celsius it will convert both
System.out.println("Select which temperature scale you currently use, (c)elsius or (f)ahrenheit: ");
temperatureScale = scannerIn.next();
System.out.println("Temp in C is: " + temperatureInC);
*/
if (temperatureScale.equals("c")) {
System.out.println("Please enter the temperature in Celsius: ");
temperatureInC = scannerIn.nextDouble();
}
else {
System.out.println("Please enter the temperature in Fahrenheit: ");
temperatureInF = scannerIn.nextDouble();
}
tempInCelsiusConvFromFahrenheit = (temperatureInF - 32) * 5/9;
tempInFahrenheitConvFromCelsius = (temperatureInC * 9/5) + 32;
averageQuizScore = ((quiz1 + quiz2 + quiz3)/3);
System.out.println("*** Thank You ***");
System.out.println("Student EMPLID:" + studentID);
System.out.println("Quiz 1 Score: " + quiz1);
System.out.println("Quiz 2 Score: " + quiz2);
System.out.println("Quiz 3 Score: " + quiz3);
System.out.println("Average quiz score: " + df2.format(averageQuizScore));
System.out.println("Age in months: " + age * 12);
System.out.println("Age in years: " + age);
System.out.println("Temperature in Celsius: " + tempInCelsiusConvFromFahrenheit + '°');
System.out.println("Temperature is Fahrenheit: " + tempInFahrenheitConvFromCelsius + '°');
}
}
I selected celsius and enter 32. and thought I would get 32 C and 91.4 but I got: Temperature in Celsius: -17.77777777777778° Temperature is Fahrenheit: 91.4°