Jump to content
The Official Site of the Vancouver Canucks
Canucks Community

C# Programming Help


Zigmund.Palffy

Recommended Posts

Hi there , Just need some help on C# programming hopefully there are some people on this forum who are programmers !

Im trying to convert Celsius to Fahrenheit and having some trouble , basically dont know how the code works, and on top of that I need to put it in a ListBox.

anyone that can help ?

F= 9/5 C + 32 this is the formula

i just need to make sure the Celsius Temperature is equivalent to Fahrenheit temperature

Link to comment
Share on other sites

I'm more of a C++ guy myself, but your function should probably look a little something like this:


private void Celsius_Click(object sender, EventArgs e)


	    {


		    double dblFahrenheit;


		    double dblCelsius;


		    dblFahrenheit = double.Parse(Celsius.Text);


		    dblCelsius = (Fahrenheit - 32) * 5 / 9;


		    Fahrenheit.Text = Convert.ToString(dblFahrenheit);

	    }

I grabbed that from this link: http://www.codeproject.com/Questions/183552/C-program-converting-Fahrenheit-Celsius-Kelvin so don't give me too much credit. Hope that helps. :)

There's a function there to go from Fahrenheit back to Celsius, too.

Link to comment
Share on other sites

I'm more of a C++ guy myself, but your function should probably look a little something like this:


private void Celsius_Click(object sender, EventArgs e)


		{


			double dblFahrenheit;


			double dblCelsius;


			dblFahrenheit = double.Parse(Celsius.Text);


			dblCelsius = (Fahrenheit - 32) * 5 / 9;


			Fahrenheit.Text = Convert.ToString(dblFahrenheit);

		}

I grabbed that from this link: http://www.codeproje...-Celsius-Kelvin so don't give me too much credit. Hope that helps. :)

There's a function there to go from Fahrenheit back to Celsius, too.

Link to comment
Share on other sites

Okay, what it sounds like you're trying to do is be able to fill a listbox with Celsius temperatures, and then press a button and convert them all into Fahrenheit, and store the results into another listbox? Is that right?

Because if so, then the above code just needs to loop over each element in the celsius list, and put the result into the fahrenheit one. Something like this:


private void Fahrenheit_Click(object sender, EventArgs e)

			    {

					    double dblFahrenheit;

					    double dblCelsius;


	  foreach (string CelsiusValue in ListBoxCelsius.Items){


	   dlbCelsius = double.Parse(CelsiusValue);


	   dblFahrenheit = (Celsius * 9 / 5) + 32;


	   ListBoxFahrenheit.Items.Add(dblFahrenheit.ToString());

	  }

			    }

Link to comment
Share on other sites

Okay, what it sounds like you're trying to do is be able to fill a listbox with Celsius temperatures, and then press a button and convert them all into Fahrenheit, and store the results into another listbox? Is that right?

Because if so, then the above code just needs to loop over each element in the celsius list, and put the result into the fahrenheit one. Something like this:


private void Fahrenheit_Click(object sender, EventArgs e)

				{

						double dblFahrenheit;

						double dblCelsius;


	  foreach (string CelsiusValue in ListBoxCelsius.Items){


	   dlbCelsius = double.Parse(CelsiusValue);


	   dblFahrenheit = (Celsius * 9 / 5) + 32;


	   ListBoxFahrenheit.Items.Add(dblFahrenheit.ToString());

	  }

				}

Link to comment
Share on other sites

okay heres what its asking for ...

it says Create an application that displays a table of the celsius temperature 0-20 and their Fahrenheit equivalents. The application should use a loop to display the temperatures in a List Box.

Not 2 list boxes only ONE list box

this is the question.

Link to comment
Share on other sites

There should be a function to run when the form loads. Try putting this code in there:


for (double dblCelsius = 0; dblCelsius < 20; dblCelsius++){

string outputString;

double dblFahrenheit;

dblFahrenheit = (dblCelsius * 9 / 5) + 32;



outputString = "Celsius: " + dblCelsius.ToString() + " Fahrenheit: " dblFahrenheit.ToString();

ListBoxTemperatures.Items.Add(outputString);


}

Link to comment
Share on other sites

okay i got this problem i got this error


private void calculateButton_Click(object sender, EventArgs e)

		{

			double dblFahrenheit;

			double dblCelsius;


			for (double [u]dblCelsius[/u] = 0; dblCelsius < 20; dblCelsius++)

			{

			string outputString;

			double [u]dblFahrenheit[/u];

			dblFahrenheit = (dblCelsius * 9 / 5) + 32;



			outputString = "Celsius: " + dblCelsius.ToString() + " Fahrenheit: " [u]dblFahrenheit[/u].ToString();

			ListBoxTemperatures.Items.Add(outputString);

underlines mean its errors :S

Link to comment
Share on other sites

okay i got this problem i got this error


private void calculateButton_Click(object sender, EventArgs e)

		{

			double dblFahrenheit;

			double dblCelsius;


			for (double [u]dblCelsius[/u] = 0; dblCelsius < 20; dblCelsius++)

			{

			string outputString;

			double [u]dblFahrenheit[/u];

			dblFahrenheit = (dblCelsius * 9 / 5) + 32;



			outputString = "Celsius: " + dblCelsius.ToString() + " Fahrenheit: " [u]dblFahrenheit[/u].ToString();

			ListBoxTemperatures.Items.Add(outputString);

underlines mean its errors :S

Link to comment
Share on other sites

It was the extra declarations, this works:


		double dblFahrenheit;					  

		double dblCelsius;										

		for (dblCelsius = 0; dblCelsius < 20; dblCelsius++)

		{

			string outputString;

			dblFahrenheit = (dblCelsius * 9 / 5) + 32;

			outputString = String.Format("Celsius: {0} Fahrenheit: {1}", dblCelsius.ToString(),dblFahrenheit.ToString());

			ListBoxTemperatures.Items.Add(outputString);

	 }

Cheers

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...