This program inputs temperature readings. Works easy in C++ but it's more difficult in Java. The current error I'm getting is the compiler is telling me "ch cannot be resolved to a variable." How can I fix this? The user enters 'y' telling the program he wants to enter another temperature reading, or else he enters 'n' which should break the loop and end the program and calculate the results.
import java.util.Scanner; public class TemperatureReadings { public static void main(String args[]) { Scanner myScanner = new Scanner(System.in); int count = 0; double temperature = 0.0; double average = 0.0; do { System.out.print("Enter a temperature reading: "); temperature = myScanner.nextDouble(); average += temperature; count++; System.out.print("Do you want to enter another? (y/n)"); char ch = myScanner.next().charAt(0); // right here compiler error } while(ch == 'y'); average /= count; System.out.println("The average temperature reading is " + average); } }