5 Replies - 1292 Views - Last Post: 03 June 2011 - 04:13 PM Rate Topic: -----

#1 Sonicdeath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 11

Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 01:16 PM

I'm having a problem with assigning multiple values to a double to produce an output.

I have to assign the following values in celsius and convert to Fahrenheit:
Celsius Fahrenheit
40 convert
39 convert
32 convert
31 convert

Will I need to use a loop for this?

I hate asking for help because I'm really getting into Java but I am really stuck on this. Any direction would be
very much appreciated.

package conversion;
import java.util.Scanner;
/**
 *
 * @author Darin
 */
public class ConversionProgram {

public static void main(String[] args) {
        
Scanner input = new Scanner(System.in);
        //variables
        int menuOption;
        double celsius;
        double fahrenheit;
        double foot;
        double meters;

//Select option

System.out.println("Select 1 for Temperature Conversion Table");
System.out.println("Select 2 for Measurement Conversion Table");



    menuOption = input.nextInt();

    while (menuOption !=0)
    {
     if(menuOption <0 || menuOption >2)
     System.out.println("Please enter a valid option!");

     switch (menuOption){
     case 1: celsiusToFahrenheit();
        }
     break;
     
    }
       
    }
//convert celsius to fahrenheit

 public static double celsiusToFahrenheit() {
       double celsius = 0;
       double fahrenheit;

       fahrenheit = ( 9.0/5 ) * celsius + 32;
       
       System.out.println("\tFahrenheit \t  Celcius\n");
       System.out.println("\t   " + fahrenheit + "\t\t " + celsius +"\n");
       return fahrenheit;
}

}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Fahrenheit to Celsius Program problem with assigning values to double

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 01:43 PM

But here you set celsius to 0, which does`t give logic. You need to ask user to input value for celsius, is n`t it?
Was This Post Helpful? 0
  • +
  • -

#3 Sonicdeath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 11

Re: Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 02:10 PM

View Postsmohd, on 03 June 2011 - 01:43 PM, said:

But here you set celsius to 0, which does`t give logic. You need to ask user to input value for celsius, is n`t it?

When the user selects option 1 it is supposed to bring up the table data and perform the calculations on each of those values.
I don't think there is user input. I had it done that way with using input.nextDouble() but that was incorrect.
Sorry i may have worded it wrong, I assigned 0 b/c i'm stuck on it and just put it there for now. I'm not sure if I should use an array, really frustrated with it that I havent figured it out.
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 02:20 PM

Then if you have your already value, use array and loop between them.
Was This Post Helpful? 1
  • +
  • -

#5 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 03:57 PM

As been said, your answer at the moment will always be 0. You have 2 options. Ask the user to input a celcius value (which would make most sense to do), or you could hardcode the values and just print out the results. Whether you need a loop for this second options depends on the approach you take. You can store them in individual variables, therefore no loop is required. Or as said, you can use an Array, and then it would make more sense to use a loop.
Was This Post Helpful? 1
  • +
  • -

#6 Sonicdeath  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-June 11

Re: Fahrenheit to Celsius Program problem with assigning values to double

Posted 03 June 2011 - 04:13 PM

Thanks for the replies I appreciate the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1