Results 1 to 4 of 4
  1. #1
    bosoxfan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default Fahrenheit to Celcius program error

    Hello everyone,

    I am new to Java Forums and also new to Java programming. I have made a program that allows a user to choose to convert a temperature to either farenheit or celcius and I am getting an error that I cant seem to resolve and was hoping that someone may be able to help me out. The error I am getting is the compiler is stating that i need to declare Farenheit and celcius which I have done in the beginning but yet I am still getting an error. Here is my code for your review:

    --------------------------------------------------------------------------

    import java.util.Scanner;

    public class FtoCtoF
    {
    public static void main(String[] args)
    {
    Scanner input = new Scanner (System.in);

    System.out.println ("Welcome to the tempterature converter");
    System.out.println ("Please select 1 to convert from Farenheit to Celcius");
    System.out.println ("Please select 2 to covert from Celcius to Farenheit");

    int inputNum = input.nextInt();
    double farenheit;
    double celcius;

    if (inputNum == 1)
    {
    System.out.println("Please enter the Farenheit temperature you want to convert to Celcius");
    celcius = input.nextDouble();
    celcius = (5.0/9) * (farenheit - 32);
    System.out.println ("The celcius temperature is:" + celcius);
    }

    else if (inputNum == 2)
    {
    System.out.println ("Please enter the Celcius temperature you want to conver to Farenheit");
    farenheit = input.nextDouble();
    farenheit = (9.0/5) * (celcius + 32);
    System.out.println ("The farenheit temperature is:" + farenheit);
    }
    }
    }



    Thanks in advance for any help.

  2. #2
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

    Default

    Solution:


    import java.util.Scanner;

    public class FtoCtoF
    {
    public static void main(String[] args)
    {
    Scanner input = new Scanner (System.in);

    System.out.println ("Welcome to the tempterature converter");
    System.out.println ("Please select 1 to convert from Farenheit to Celcius");
    System.out.println ("Please select 2 to covert from Celcius to Farenheit");

    int inputNum = input.nextInt();
    double farenheit=0.0;
    double celcius=0.0;

    if (inputNum == 1)
    {
    System.out.println("Please enter the Farenheit temperature you want to convert to Celcius");
    farenheit = input.nextDouble();
    celcius = (5.0/9.0) * (farenheit - 32);
    System.out.println ("The celcius temperature is:" + celcius);
    }

    else if (inputNum == 2)
    {
    System.out.println ("Please enter the Celcius temperature you want to conver to Farenheit");
    celcius = input.nextDouble();
    farenheit = (9.0/5.0) * (celcius + 32);
    System.out.println ("The farenheit temperature is:" + farenheit);
    }
    }
    }

  3. #3
    bosoxfan is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Aseem,

    Thank you very much for your help. I figured it was going to be something relatively easy but I spent hours trying to resolve on my own. Now I know next time to come to a place like this and ask for help if my own research turns up nothing!

    Thank you again!!! :)

  4. #4
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

Similar Threads

  1. Program Error Help!!!
    By arrech326 in forum New To Java
    Replies: 6
    Last Post: 11-18-2009, 12:16 PM
  2. Help with fahrenheit to celsius conversion
    By java_is_killingme in forum New To Java
    Replies: 4
    Last Post: 03-07-2009, 11:11 AM
  3. I can't fix this runtime error in my program
    By Sinnergy in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 04:29 PM
  4. Fahrenheit to celsius
    By lalithalydia in forum New To Java
    Replies: 3
    Last Post: 02-05-2008, 07:50 AM
  5. Converts from Fahrenheit to Celsius
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •