How do I convert a variable and then store it into another variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Janaya Scott

    #1

    How do I convert a variable and then store it into another variable?

    I'm working on a computer program for converting temperatures into other temperatures. Like I'm suppose to convert the temperature to celsius and store in newTemp variable. And then I'm suppose display the original temp and the new temperature with their scales. I'm just lost my if function isn't working and im not sure which console to use. Please help I hope this is clear.

    Code:
    using System;
    class temperature
    {
        static void Main()
        {
            // Variables that hold data and info in the RAM
           double temperature, newTemp, scale, userAnswer;
        do
        { 
            Console.WriteLine("Enter a temperature (decimals are excepted).");
            temperature = Convert.ToDouble(Console.ReadLine());
    
            Console.WriteLine("Enter c or f.");
            scale = Convert.ToDouble(Console.ReadLine());
        
            if (scale is "f" )
  • Luke Hackel
    New Member
    • Oct 2010
    • 2

    #2
    I'm not completely sure what you mean, but this might be what you mean:

    Code:
    using System;
    
    class temp
    {
    	static void Main()
    	{
    	    //variables to store
    	    double temperature;
    	    double newTemp;
    	    char scale;
    	    double userAnswer;
    
    		do
    		{
    		Console.WriteLine("enter temp:");
    		temperature = Convert.ToDouble(Console.ReadLine());
    
    		Console.WriteLine("enter c or f:");
    		scale = Console.ReadLine().ToCharArray()[0]; //there is a FAR FAR neater
    		//way of doing this, I just dont have an IDE to hand
    
    		if (scale = 'f')
    		{
    		    newTemp = temperature;
    		    newTemp = (scale calulcation here)
    		    Console.WriteLine(temperature + " *F as *C is " + newTemp);
    		}
    		
    		}
    	}
    }

    Comment

    Working...