473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. class temperature
  3. {
  4.     static void Main()
  5.     {
  6.         // Variables that hold data and info in the RAM
  7.        double temperature, newTemp, scale, userAnswer;
  8.     do
  9.     { 
  10.         Console.WriteLine("Enter a temperature (decimals are excepted).");
  11.         temperature = Convert.ToDouble(Console.ReadLine());
  12.  
  13.         Console.WriteLine("Enter c or f.");
  14.         scale = Convert.ToDouble(Console.ReadLine());
  15.  
  16.         if (scale is "f" )
  17.  
Oct 5 '10 #1
1 1232
I'm not completely sure what you mean, but this might be what you mean:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. class temp
  4. {
  5.     static void Main()
  6.     {
  7.         //variables to store
  8.         double temperature;
  9.         double newTemp;
  10.         char scale;
  11.         double userAnswer;
  12.  
  13.         do
  14.         {
  15.         Console.WriteLine("enter temp:");
  16.         temperature = Convert.ToDouble(Console.ReadLine());
  17.  
  18.         Console.WriteLine("enter c or f:");
  19.         scale = Console.ReadLine().ToCharArray()[0]; //there is a FAR FAR neater
  20.         //way of doing this, I just dont have an IDE to hand
  21.  
  22.         if (scale = 'f')
  23.         {
  24.             newTemp = temperature;
  25.             newTemp = (scale calulcation here)
  26.             Console.WriteLine(temperature + " *F as *C is " + newTemp);
  27.         }
  28.  
  29.         }
  30.     }
  31. }
Oct 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: harishg2 | last post by:
Hi, How to store a variable value for more than one executions. Ex: main() { int i=0; i++; printf("%d",i);
1
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, Is it possible to store double variable to session? If possible can show me code sample on how to convert.Thanx n advance. -- Message posted via http://www.dotnetmonster.com
9
by: keliie | last post by:
Hello (from Access novice), I'm building a switchboard form (using a Treeview object). The treeview is populated by two tables (tblSwitchboardParent and tblSwitchboardChild). Within...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
6
by: Busbait | last post by:
I need to know how can I store SQL result into variable, I have used the below code but it dose not work. Is there an easier way to do this? ...
4
by: wish | last post by:
Hi all, Where is the location for store session variable? Because i feel that the session variable is keep store the previous variable and no release the variable. When i click back button,...
0
by: becksinthecity | last post by:
I'm trying to convert the below SQL into Oracle but am having some issues with the variable declarations. SQL commands declare @sqlstring varchar(500) select @sqlstring= (select ...
2
by: Whasigga | last post by:
Hello I am working on a project to export data from a query into an Excel file. I have a form with a button on it and the button when clicked runs a function that is supposed to run the query and...
4
by: Gunnar Hurtig | last post by:
How do I convert a string name into a variable name? example L= I want to create two variables from L so that I can assign values to them. say a=4
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.