7 Replies - 1580 Views - Last Post: 25 February 2011 - 09:14 AM Rate Topic: -----

#1 Cdat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 11

Errors in Temperature Conversion Program

Posted 25 February 2011 - 08:52 AM

Good day all,

I have been trying to write a celsius to fahrenhiet conversion program that also uses a loop function. I have tried compiling what I have but I end up with 12 errors but they all seem to be in the same line. If anyone would please help me out on trying to find my errors. Thanks in advance for any help given.

/*****************************************************************
* Tempconversion2.java
* Corie 
*
* This program prints Temp Converisions.
*****************************************************************/
import java.util.Scanner;

public class Tempconversion2
{
  public static void main(String[] args)
    {
    Scanner stdIn = new Scanner (System.in);
    double Temp ;    // degrees in Celsius
    double Conversion = (1.8 * Celsius) + 32;  // temperature in Fahrenhiet
    char response;           // user's y/n response
    
    System.out.print ("Enter Temperature In Celsius:  ");
    Temperature = stdIn.nextDouble();
    System.out.print ("Would you like to try anymore conversions?  (Y/N): ");
    response = stdIn.next() .charAt (0);
    } while  (response == 'y' || response == 'Y');
              
System.out.println ("Temperature in Celsius converts to " + Conversion);
      

  } //end main
} // end class Tempconversion2


All errors seem to be on line 22.

Is This A Good Question/Topic? 0
  • +

Replies To: Errors in Temperature Conversion Program

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 08:55 AM

You have a closing bracket on line 22 just before the while loop. This is the most likely culprit of your issues. Remove it, and try again.
Was This Post Helpful? 0
  • +
  • -

#3 TFoSSDQ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 123
  • View blog
  • Posts: 253
  • Joined: 09-December 10

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 08:57 AM

Your problem isn't difficult, on line 22, what is that closing curly brace closing? And what is the purpose of the while loop? Think about it a bit :).
Was This Post Helpful? 0
  • +
  • -

#4 Cdat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 11

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 09:01 AM

will do thanks for such a quick reply.

View PostTFoSSDQ, on 25 February 2011 - 08:57 AM, said:

Your problem isn't difficult, on line 22, what is that closing curly brace closing? And what is the purpose of the while loop? Think about it a bit :).


I am using the while loop so that users can add more that one temp to convert. Unless I am doing it wrong.
Was This Post Helpful? 0
  • +
  • -

#5 TFoSSDQ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 123
  • View blog
  • Posts: 253
  • Joined: 09-December 10

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 09:05 AM

there are two types of while loops, a while with a code block, and a do while. The syntax for a regular while loop is:
while(condition)
{
     //do code
}



The syntax for a do while is:
do
{
     //do code
} while(condition);



The do while loop will iterate AT LEAST once and then checks the condition after. The regular while loop checks the condition at the start.
Was This Post Helpful? 0
  • +
  • -

#6 Cdat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 11

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 09:07 AM

View PostTFoSSDQ, on 25 February 2011 - 09:05 AM, said:

there are two types of while loops, a while with a code block, and a do while. The syntax for a regular while loop is:
while(condition)
{
     //do code
}



The syntax for a do while is:
do
{
     //do code
} while(condition);



The do while loop will iterate AT LEAST once and then checks the condition after. The regular while loop checks the condition at the start.



Ok thanks for your help in this I understand a bit better now.
Was This Post Helpful? 0
  • +
  • -

#7 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 09:11 AM

The while loop currently isn't going to work the way you want it to. What you'll have to do is create a while loop to check response for input that you decide will close the program. Just for arguments sake, let's say we use N as the command for exiting the program since you've already got it displayed in the question for converting more temperatures. You'll want your while loop to look something similar to while (response != "n" || response != "N") Then inside that loop you'll need to add the code for allowing the user to input a temperature and convert that temperature. The way you currently have it written, all of the code that handles the temperature is outside of the loop and therefore will not loop and allow the user to input anything after the first temperature. I've never claimed to be an expert at Java, so here's my attempt at this issue:
public static void main(String[] args)
{
    Scanner stdIn = new Scanner (System.in);
    double Temp ;    // degrees in Celsius
    char response;           // user's y/n response

    while  (response != 'n' || response != 'N')
    {
        System.out.print ("Enter Temperature In Celsius:  ");
        Temperature = stdIn.nextDouble();
        System.out.print ("Would you like to try anymore conversions?  (Y/N): ");
        response = stdIn.next() .charAt (0);
        double Conversion = (1.8 * Temp) + 32;  // temperature in Fahrenhiet
        System.out.println ("Temperature in Celsius converts to " + Conversion);
    }
}



So there's my attempt at this issue without any way of actually testing it, so I hope it helps you in some way.

This post has been edited by Kilorn: 25 February 2011 - 09:14 AM

Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: Errors in Temperature Conversion Program

Posted 25 February 2011 - 09:14 AM

Please do not use topic titles like "Noob needs help". We KNOW you need help or you wouldn't be here posting a question! Use a descriptive title like that to which I've changed yours.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1