View Single Post
Old Jun 9th, 2005, 1:44 PM   #25
shangnyun
Programmer
 
shangnyun's Avatar
 
Join Date: Jun 2005
Posts: 34
Rep Power: 0 shangnyun is on a distinguished road
Quote:
Originally Posted by Knight
*** Messed up a bit. Can't fix just yet. Have to run. Fix later ***

Place it in a while loop. Insert the following:

                 

    		System.out.println("Next, please enter either \"C\" or \"c\" for a");
    		System.out.println("Celsius-Fahrenheit conversion, or \"F\" or \"f\"");
    		System.out.println("for a Fahrenheit-Celsius conversion:");
			System.out.println();
                                      
//			typeOfConversion = (char)typeOfConversion;
			typeOfConversion = keyboard.next();
                        while(typeOfConversion.charAt(0).equalsIgnoreCase(c) || typeOfConversion.charAt(0).equalsIgnoreCase(f))
                       {
			switch (typeOfConversion.charAt(0))
			{
				case 'C':
				case 'c':
					result = 5.0 * ((double)degreeValue - 32.0) / 9.0;
					System.out.println();
					System.out.println(degreeValue + " Fahrenheit is " + result + " Celsius");
					break;
				case 'F':
				case 'f':
					result = (9.0 * ((double)degreeValue) / 5.0) + 32.0;
					System.out.println();
					System.out.println(degreeValue + " Celsius is " + result + " Fahrenheit");
					break;
				default:
		    		System.out.println();
					System.out.println("Oops! Your entry is invalid. Please enter either");
					System.out.println("\"F\" or \"C\". The letter case does not matter.");
					break;
			}
}

That should work
Shouldn't it be whlie (The input does NOT EQUAL C, c, F, f)???

Because the user is supposed to REDO it if it doesn't. If it DOES equal those chars, which is what your while statement suggests, why would the user want to re-go through the loop??
shangnyun is offline   Reply With Quote