# Problem converting F to C vise versa

• (2 Pages)
• 1
• 2

## 24 Replies - 3032 Views - Last Post: 02 October 2012 - 03:04 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=293741&amp;s=c7e53309a2fe254358c123432b769370&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

# Problem converting F to C vise versa

Posted 30 September 2012 - 12:21 PM

Ok I cant figure out how to get this to work i know the formula to convert them but i cant seem to understand how to put them in java language any insight is appreciated. I have no idea what to do for the system.out.print neither. Because i cant even get the formula into java language

```public class Temps
{
public static void main (String[] args)
{
// Define constants

final double celsius;
final double fahrenheit;

// Display prompt for temperature in degrees Farhenheit or Celsius
System.out.print("Please enter the temperature in degrees: ");

Scanner in = new Scanner(System.in);
double temp = in.nextDouble();

// Display prompt for character that denotes type of temperature
System.out.print("Enter F for Farhenheit or C for Celsius: ");

// Read character denoting type of temperature
String type = in.next();

// Compute and print Celsius or Farhenheit equivalent

if(type.equalsIgnoreCase("f"))
fahrenheit = (9/5)celsius + 32);
System.out.println(temp + " Farhenheit = " + result + " Celsius.");

if(type.equalsIgnoreCase("c"))
celsius = (5/9)(fahrenheit - 32.0)
System.out.println(temp + " Celsius = " + result + " Fahrenheit.");

}
}

```

This post has been edited by rbk3ai: 30 September 2012 - 12:26 PM

Is This A Good Question/Topic? 0

## Replies To: Problem converting F to C vise versa

### #2 natecat

Reputation: 57
• Posts: 233
• Joined: 19-December 11

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 12:35 PM

First thing I noticed is that you have a extra parentheses hanging around on this line:
```fahrenheit = (9/5)celsius + 32);
```

and on this line you forgot a semicolon:
```celsius = (5/9)(fahrenheit - 32.0)
```

### #3 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 12:40 PM

natecat, on 30 September 2012 - 12:35 PM, said:

First thing I noticed is that you have a extra parentheses hanging around on this line:
```fahrenheit = (9/5)celsius + 32);
```

and on this line you forgot a semicolon:
```celsius = (5/9)(fahrenheit - 32.0)
```

```Temp.java:16: ')' expected
fahrenheit = (9/5 celsius + 32);
^
Temp.java:16: not a statement
fahrenheit = (9/5 celsius + 32);

```

```Temp.java:20: ';' expected
celsius = (5/9)(fahrenheit - 32.0);
^
Temp.java:20: not a statement
celsius = (5/9)(fahrenheit - 32.0);

```

This post has been edited by rbk3ai: 30 September 2012 - 12:47 PM

### #4 natecat

Reputation: 57
• Posts: 233
• Joined: 19-December 11

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 12:42 PM

The ending one, not the middle one

### #5 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 12:50 PM

```Temp.java:16: not a statement
fahrenheit = (9/5)celsius + 32;

```

### #6 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 01:03 PM

Any other help? I've tried what you suggested still doesn't help.

### #7 natecat

Reputation: 57
• Posts: 233
• Joined: 19-December 11

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 01:33 PM

You need to have some sort of operation between the (9/5) and the celcius variable

### #8 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 01:39 PM

natecat, on 30 September 2012 - 01:33 PM, said:

You need to have some sort of operation between the (9/5) and the celcius variable

like this
```Temp.java:20: variable celsius might not have been initialized
fahrenheit = (9/5) + celsius + 32;
^
Temp.java:17: variable fahrenheit might not have been initialized
celsius = (5/9) + fahrenheit - 32.0;

```

This post has been edited by rbk3ai: 30 September 2012 - 01:46 PM

### #9 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:00 PM

Please post the latest version of the code and describe the latest problems, errors, questions, etc. It's very hard to determine the current status from the latest post when one has to go back to the first post and add in all of the snippets posted since.

Relax, take a breath, it'll be okay.

### #10 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:02 PM

GregBrannon, on 30 September 2012 - 02:00 PM, said:

Please post the latest version of the code and describe the latest problems, errors, questions, etc. It's very hard to determine the current status from the latest post when one has to go back to the first post and add in all of the snippets posted since.

Relax, take a breath, it'll be okay.

I haven't got much greg, but this is where I'm at. Also, whats the best way to teach this stuff my teacher gave us a book from 2006 and Im lost i want to learn on my own i dont like the teaching system.

```import java.util.Scanner;

public class Temp
{
public static void main (String[] args)
{
final double celsius;
final double fahrenheit;
System.out.print("Please enter the temperature in degrees: ");
Scanner in = new Scanner(System.in);
double temp = in.nextDouble();
System.out.print("Enter F for Farhenheit or C for Celsius: ");
String type = in.next();

if(type.equalsIgnoreCase("f"))
fahrenheit = (9/5) * celsius + 32.0;

if(type.equalsIgnoreCase("c"))
celsius = (5/9) * fahrenheit - 32.0;
}
}

```

This post has been edited by rbk3ai: 30 September 2012 - 02:04 PM

### #11 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:09 PM

In Java (5/9) will not give you the result you expect. It is integer division so will be rounded. Instead do (5.0 / 9.0) which is double arithmetic and will give you a decimal result.

### #12 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:15 PM

I get this how to fix it? I cant initialize it can i? because it will change if someone picks different numbers?

```Temp.java:16: variable celsius might not have been initialized
fahrenheit = (9.0/5.0) * celsius + 32.0;
^
Temp.java:19: variable fahrenheit might not have been initialized
celsius = (5.0/9.0) * fahrenheit - 32.0;

```

This post has been edited by rbk3ai: 30 September 2012 - 02:18 PM

### #13 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:34 PM

You are repeating mistakes because you don't understand the use of variables and their many possible flavors.

Why are celsius and fahrenheit final? (And if final, how can you expect to declare them without initializing them?)

An alternative at your stage is to declare static or class variables, and, as pointed out before, modify your equations so that a decimal number will result from a division:
```import java.util.Scanner;

public class TestClass3
{
static double celsius;
static double fahrenheit;

public static void main (String[] args)
{
System.out.print("Please enter the temperature in degrees: ");
Scanner in = new Scanner(System.in);
double temp = in.nextDouble();
System.out.print("Enter F for Farhenheit or C for Celsius: ");
String type = in.next();

if(type.equalsIgnoreCase("f"))
fahrenheit = (9.0/5.0) * celsius + 32.0;

if(type.equalsIgnoreCase("c"))
celsius = (5.0/9.0) * fahrenheit - 32.0;
}
}
```

You still need to print out the answer.

These are pretty basic concepts that you've missed along the way. If you want to succeed in this course, you need to reprioritize this class in your study schedule and catch up. Ya, I know, the instructor is lacking, but use the resources that are available to you to make up for his/her shortcomings. It's your fate over which you have some responsibility and control, not the instructor's.

### #14 rbk3ai

Reputation: -4
• Posts: 64
• Joined: 08-September 12

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:41 PM

Thanks!

This post has been edited by rbk3ai: 30 September 2012 - 02:43 PM

### #15 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Problem converting F to C vise versa

Posted 30 September 2012 - 02:47 PM

Quit posting snippets that make no sense without the context of the rest of the program. Look at what I posted, because it works without error. Figure out why what you've done is wrong based on my error-free example. But I, or anyone else, can't help you, because I/we don't know what your program looks like.

Edit: Okay, I guess you reworked what you'd done, and discovered the solution. Happy day!

This post has been edited by GregBrannon: 30 September 2012 - 02:48 PM