Results 1 to 4 of 4
- 02-10-2010, 03:19 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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.
- 02-10-2010, 03:30 AM #2
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
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);
}
}
}
- 02-10-2010, 03:36 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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!!! :)
- 02-10-2010, 03:38 AM #4
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
Similar Threads
-
Program Error Help!!!
By arrech326 in forum New To JavaReplies: 6Last Post: 11-18-2009, 12:16 PM -
Help with fahrenheit to celsius conversion
By java_is_killingme in forum New To JavaReplies: 4Last Post: 03-07-2009, 11:11 AM -
I can't fix this runtime error in my program
By Sinnergy in forum New To JavaReplies: 5Last Post: 02-25-2009, 04:29 PM -
Fahrenheit to celsius
By lalithalydia in forum New To JavaReplies: 3Last Post: 02-05-2008, 07:50 AM -
Converts from Fahrenheit to Celsius
By trill in forum New To JavaReplies: 1Last Post: 08-06-2007, 05:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks