0

I'm making a program which convert Celsius to Fahrenheit and opposing too but I have a bug when you say you want to convert another value. Please can someone find and solve the problem it is since 2 days I'm searching.

import java.util.Scanner; public class Conversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double converted=0; char answer=' ', choice= ' '; System.out.println("Convertion of Celsius and Farenheit degrees"); do{ do{ System.out.println("Choose the unit of the number you'll type in C/F"); choice = sc.nextLine().charAt(0); if(choice != 'C' && choice != 'F') System.out.println("Unknown unit, retry."); }while (choice != 'C' && choice != 'F'); System.out.println("Temperature"); while(!sc.hasNextDouble()) { System.out.println("This isn't a number, retry."); sc.next(); } double toConvert = sc.nextDouble(); sc.nextLine(); if(choice == 'C'){ converted = ((9.0/5.0) * toConvert) + 32.0; System.out.print(toConvert + " °C is : "); System.out.println((converted) + "in °F."); } else{ converted = ((toConvert - 32) * 5) / 9; System.out.print(toConvert + " °F is "); System.out.println((converted) + "in °C."); } do{ System.out.println("Do you want to convert another temperature ?(Y/N)"); Scanner sc1 = new Scanner(System.in); answer = sc1.nextLine().charAt(0); sc1.close(); sc1.nextLine(); }while(answer != 'Y' && answer != 'N'); }while(answer == 'Y'); System.out.println("Bye!"); sc.close(); } }

8th Jul 2016, 8:39 PM
Greveson Axel
Greveson Axel - avatar
1 Answer
0
first of all there's an error undefined variable choix I think that's a typo though at while(choice != 'c' && choice!= 'f') Remove sc1.close and sc1.next line at your last do while loop
9th Jul 2016, 7:54 AM
Ore Falomo
Ore Falomo - avatar