Jump to content

Welcome to canucks.com Vancouver Canucks homepage

Photo

C# Programming Help


This topic has been archived. This means that you cannot reply to this topic.
18 replies to this topic

#1 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 03:20 PM

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

#2 uber_pwnzor

uber_pwnzor

    Canucks Regular

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,451 posts
  • Joined: 07-December 11

Posted 14 October 2012 - 03:24 PM

Isn't it better to do this in Excel?

#3 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 03:26 PM

Isn't it better to do this in Excel?


No it has to be in C# , I need to make a program for it

#4 uber_pwnzor

uber_pwnzor

    Canucks Regular

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,451 posts
  • Joined: 07-December 11

Posted 14 October 2012 - 03:31 PM

So basically you need to make a program where you type in a number and it converts it?

Edited by Grammar Police, 14 October 2012 - 03:31 PM.


#5 SkeeterHansen

SkeeterHansen

    Canucks Third-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 3,142 posts
  • Joined: 24-May 11

Posted 14 October 2012 - 03:35 PM

Whoa, math.

/=S=/


#6 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 03:41 PM

So basically you need to make a program where you type in a number and it converts it?


no not type it when you click a button it will automatically convert it to Fahrenheit..

i have to convert these numbers to from Celsius to Fahrenheit (0-20)

I just need help on the coding

#7 Raiun

Raiun

    Canucks Prospect

  • Members
  • PipPipPipPipPipPipPip
  • 1,112 posts
  • Joined: 23-February 12

Posted 14 October 2012 - 03:49 PM

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.

#8 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 03:56 PM

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.


yea Looked at that before not exactly what im looking for but its on the right track

instead of having seperate buttons for Celsius and Fahrenheit, I need one for just converting Celsius to Fahrenheit and it gotta be in a Listbox

#9 Raiun

Raiun

    Canucks Prospect

  • Members
  • PipPipPipPipPipPipPip
  • 1,112 posts
  • Joined: 23-February 12

Posted 14 October 2012 - 04:10 PM

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());
	  }
			    }


#10 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 04:15 PM

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());
	  }
				}


yes thats it ! |Sorry forgot to mention the loop part my bad !

but yes i think thats it i believe let me try it i will get back to u in a second !

#11 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 04:25 PM

Okay guys its not working ....

#12 Raiun

Raiun

    Canucks Prospect

  • Members
  • PipPipPipPipPipPipPip
  • 1,112 posts
  • Joined: 23-February 12

Posted 14 October 2012 - 04:28 PM

Okay guys its not working ....


Could you be a bit more specific? What piece is it breaking on? Did you make sure to name your two listboxes to match the names in the code above? (or change the code to match what you named the listboxes)?

#13 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 04:31 PM

Could you be a bit more specific? What piece is it breaking on? Did you make sure to name your two listboxes to match the names in the code above? (or change the code to match what you named the listboxes)?




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.

Edited by Zach Parise, 14 October 2012 - 04:32 PM.


#14 Raiun

Raiun

    Canucks Prospect

  • Members
  • PipPipPipPipPipPipPip
  • 1,112 posts
  • Joined: 23-February 12

Posted 14 October 2012 - 04:36 PM

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.


So you don't actually have to calculate anything, only display it?

#15 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 04:43 PM

So you don't actually have to calculate anything, only display it?


no it says to convert the numbers 0-20 from Celsius to Fahrenheit using that formula

F = 9/5 C + 32

it just says make sure to display a table in a Listbox with the Numbers converted from Celsius to Fahrenheit

#16 Raiun

Raiun

    Canucks Prospect

  • Members
  • PipPipPipPipPipPipPip
  • 1,112 posts
  • Joined: 23-February 12

Posted 14 October 2012 - 04:56 PM

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);

}


#17 Zach Parise

Zach Parise

    Canucks First-Line

  • Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 6,390 posts
  • Joined: 20-March 09

Posted 14 October 2012 - 05:42 PM

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

Edited by Zach Parise, 14 October 2012 - 05:42 PM.


#18 InTheCrease

InTheCrease

    Canucks Rookie

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,602 posts
  • Joined: 07-July 06

Posted 14 October 2012 - 08:09 PM

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


What error are you getting? I am assuming it is because you have already defined "double dblFahrenheit;", comment out or remove the one that is outside of the loop and try it again.

That or set a break point on Step through it an post the debug output where it breaks.


On a side note, look at String.Format, its way cleaner to read and saves all the "" + ""

outputString = String.Format("Celsius: {0} Fahrenheit: {1}", dblCelsius.ToString(),dblFahrenheit.ToString());
QUOTE
I played for the Leafs for three years, Im used to the booing so it wont affect me - Kyle Wellwood

#19 InTheCrease

InTheCrease

    Canucks Rookie

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,602 posts
  • Joined: 07-July 06

Posted 15 October 2012 - 09:17 AM

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

Edited by InTheCrease, 15 October 2012 - 09:18 AM.

QUOTE
I played for the Leafs for three years, Im used to the booing so it wont affect me - Kyle Wellwood




Canucks.com is the official Web site of The Vancouver Canucks. The Vancouver Canucks and Canucks.com are trademarks of The Vancouver Canucks Limited Partnership.  NHL and the word mark and image of the Stanley Cup are registered trademarks and the NHL Shield and NHL Conference logos are trademarks of the National Hockey League. All NHL logos and marks and NHL team logos and marks as well as all other proprietary materials depicted herein are the property of the NHL and the respective NHL teams and may not be reproduced without the prior written consent of NHL Enterprises, L.P.  Copyright © 2009 The Vancouver Canucks Limited Partnership and the National Hockey League.  All Rights Reserved.