0
import java.util.Scanner;

public class FHeightToCelsius {

    public static void main(String[] args)
    //Computes the Celsius equivalent of the inputted Fahrenheit value
    //using the formula C=(F-32)*5/9
    {
        final int BASE = -32;
        final double CONVERSION_FACTOR = 5/9;

        Double message;
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter A Fahrenheit:");
        message = scan.nextDouble();

        double CelsiusTemp;

        CelsiusTemp = (message + BASE) * CONVERSION_FACTOR;

        System.out.println("Your conversion is:" + CelsiusTemp);

    }
}

Math isn't my strong suit, nor is problem solving (YET!!) What I also need help with is fleshing out and understanding if this formula is right or correct and how we come about that. I looked up the formula online, but, I'm not sure if I converted it right in code.

I cannot get the math formula to work.

Abra
  • 19,142
  • 7
  • 29
  • 41
Abe Shudug
  • 125
  • 6

2 Answers2

1

The error message says it all. You're trying to perform mathematical operations on strings, that's not allowed. So turn your strings into numbers.

jwenting
  • 5,505
  • 2
  • 25
  • 30
1

I'm new to Java, but I probably know the solution to your problem.

The problem is that you are trying to add an int to a String type variable.

I suggest the following changes:

import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    //Computes the Celsius equivalent of the inputted Fahrenheit value
    //using the formula C=(F-32)*5/9
    {
        final int BASE = -32;
        // If you use the variable double you should divide 5.0 / 9
        final double CONVERSION_FACTOR = 5.0 /9;

        Scanner scan = new Scanner(System.in);
        System.out.println("Enter A Fahrenheit:");
        // to avoid the problem I described above use the nextInt() method instead of nextLine()
        int message = scan.nextInt();

        double CelsiusTemp = (message + BASE) * CONVERSION_FACTOR;
        
        // I replaced "message" with the converted value
        System.out.println("Your conversion is:" + CelsiusTemp);
    }
}

I hope I helped.

Zaburba
  • 61
  • 4