-2

I am really new to all of this stuff and I am trying to convert Celsius to Fahrenheit in jGRASP Java. The code i am using is attached in the picture, also the error can be seen in the other picture.

thats the code i am using

Error message

the following is the error

DarkBee
  • 16,592
  • 6
  • 46
  • 58
  • 1
    [Why may I not upload images of code on SO when asking a question](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question) – Monkey Supersonic Oct 22 '16 at 09:27
  • 1
    Please read http://stackoverflow.com/help/how-to-ask and reform your question according to it. – Fabian S. Oct 22 '16 at 10:03
  • 1
    Please post the relevant code, don't attach it as picture – DarkBee Oct 22 '16 at 11:29

3 Answers3

0

The message says everything. You didn't declare F yet, thus the compiler cannot find the symbol. Declare it before using it like

int F = 0;

EDIT: You probably meant to compare input with the string literal "F". You have to declare input as a string, read a string variable into it and then use the if clause like

if (input == "F") {//...
Monkey Supersonic
  • 1,165
  • 1
  • 10
  • 19
0
if (input == F)

In the code which you provided, you never declare F.

Judging by the code you want to see if the users entered an "F", however you assign the input variable as such:

int input = scan.nextInt();

It would be better to do something like this:

String input = scan.nextLine();

if(input.equals("F")){
// rest of code
a-sir
  • 74
  • 8
0

The problem with your code is you are telling the scanner to read an int data and you are expecting a text or a character. Using scanner.next() will return what comes before a space as a string . Then you can check it's value. Here is an example that does it.

public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String tempScale = "";
        System.out.print("Enter the current outside temperature: ");
        double temps = scanner.nextDouble();

        System.out.println("Celsius or Farenheit (C or F): ");
        String input = scanner.next();
        if ("F".equalsIgnoreCase(input)) {
            temps = (temps-32) * 5/9.0;
            tempScale = "Celsius.";
        } else if ("C".equalsIgnoreCase(input)) {
            temps = (temps * 9/5.0) + 32;
            tempScale = "Farenheit.";
        }
        System.out.println("The answer = " + temps + " degrees " + tempScale);
        scanner.close();
  }

And an illustration:

enter image description here

alainlompo
  • 4,414
  • 4
  • 32
  • 41