Originally Posted by
chillaxzino
I think the problem with your code is in the statement below:
int RadiusToCircumference = number1 * 2 * pi;
There are rules for working and converting between C# types. See my recommendation below:
double pi = Math.PI;
decimal number1 = Convert.ToInt32(textBox1.Text);
double RadiusToCircumference = (double)number1 * 2 * pi;
MessageBox.Show("The circumference is " + RadiusToCircumference);
These code should work based on these assumptions:
- For your own code I have assumed you are using C# 4.0 so I've done same.
- Here's what I think, if these varaible numericUpDown1.Value is of type double then that line of code should not be a problem else you'd need to explicitly cast(i.e. force a conversion from whatever type it is to type decimal) to do so just add (decimal) in front of that variable. Because I
have little idea about your numericUpDown1.Value, I initialized number1 variable from a textbox input.
As for the statement:
int RadiusToCircumference = number1 * 2 * pi;
observed that I've forced a conversion using a cast operator i.e. (double).
***********I hope these makes a good contribution to your understanding of C#***********
***********You can download my own version of your code code. See attachment.**********