|
I 'Scorn' upon your post
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Lol, 5 for being funny, 1 for making fun of me. 5 for the smiley. 5+1+5/3 = 3.66~ rounded up to 5.
|
|
|
|
|
LOL, i demand a recount!!! The scorn was in-leauge with you, and aimed at the OP, they really need to learn
P.S should it be 5.0 + 1.0 + 5.0 / 3.0 if you want it to equal 3.66?
P.P.S Nevermind, i missed you already made that joke with the rounding lol
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Scorn, I think you'll find is a noun, not a verb.
Regards,
Rob Philpott.
|
|
|
|
|
Certainly. Please send your credit card details, home address, phone number and photocopies of your signature to ExiledPrince@NigeriaMail.com. The next instant, all of your code will appear on your screen; you'll have to move out of the way though - my CodeRay is blocked by dense objects
Incidentally, a simple google search would have thrown up results regarding some of the new classes in the .Net Framework 3.5 running in Windows Vista; namely those of speech recognition. Then, you 'simply' integrate that with your own neural network
|
|
|
|
|
char a = 'A';
char b = 'B';
a = a + b;
a += b;
I thought they r both exactly the same thing. Can someone tell me whats the difference.Pl.
|
|
|
|
|
i think...
a = a + b;
is trying to assign a string (a + b) to a char (a)
where as..
a += b;
is taking them to be int values and adding 65 + 66 (ASCII values) and setting a to be 131
Atleast this is my understading
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
5'ed, I think that's correct but without looking it up I can't be sure. That makes the most sense.
|
|
|
|
|
The meaning of + operator depends on the types added together.
"A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type"
For chars the + is adding the integers together that are used for representing a single char. So in your first line the result is an int.
The second line contains automatically assignment so the result type cannot change (since you don't have an intermediate result) thus the operation results to a char. In the line having an error you must do casting explicitely to the intermediate result.
|
|
|
|
|
|
|
A colleague of mine is learning C#, as am I. I am ahead of him, so he asked me to help him figure out why his tiny test program isn't working. For the life of me I can't figure it out. Here's the code:
private void button1_Click(object sender, EventArgs e)
{
int tf = int.Parse(textBox1.Text);
int tc = 5 / 9 * (tf - 32);
label1.Text = tc.ToString();
}
This is supposed to convert the temperature in Fahrenheit (tf) to the temperature in celcius (tc). As far as I can tell it should work, but the value tc always comes out as 0. What am I overlooking?
|
|
|
|
|
Lodeclaw wrote: int tc = 5 / 9 * (tf - 32);
Integer devision, a common mistake for beginners, it happens to all of us.
5/9 is .5555 which is 0. Convert to doubles and try it then, should be fine after that.
|
|
|
|
|
|
No it isn't... I used same variable names...
double tf = double.Parse(textBox1.Text);
double tc = (5.0 / 9.0) * (tf - 32);
label1.Text = tc.ToString();
|
|
|
|
|
Oh, I see the problem. We're not entering the values in the calculation as doubles. (5.0 rather than 5) Thanks, Eliott.
|
|
|
|
|
|
Remember to change your int.Parse and datatype to double and double.Parse otherwise entering 10.0 in that textbox and parsing it to an int might either through an exception or truncate the double value (I don't know which one) in either case, duplicating the original error!!
|
|
|
|
|
double tf = double.Parse(textBox1.Text);
double tc = 5 / 9 * (tf - 32);
label1.Text = tc.ToString();
If that doesn't work, something's really wrong here.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
Kristian Sixhoej wrote: If that doesn't work, something's really wrong here.
Untrue, I think it will still do integer devision on 5 / 9, you have to explicitly put .0 on either to do double devision. Weird, I know, I just noticed that behavior on a test.
|
|
|
|
|
EliottA wrote: you have to explicitly put .0 on either to do double devision.
Didn't knew that.
EliottA wrote: Weird, I know, I just noticed that behavior on a test.
IIRC I have never had that problem when doing double divisions.
But I probably don't recall correct.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
I didn't know it either, and I never ran into a problem like that before, I never had to implicitly add a .0 unless it was in java.. even then I vaguely recall something about automatic upgrading datatype or something, I don't know. I completely forget, just remember seeing integer devision smack me in the face a few times in my first programming course.
|
|
|
|
|
EliottA wrote: I never ran into a problem like that before
That's probably because it's not that usual to divide two literal values. Usually one of the operands is a double variable, then the compiler will cast the other operand to double also.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Being a bit anal about this, I'd do this:
double tf = double.Parse(textBox1.Text);
double tc = 5d / 9d * (tf - 32d);
label1.Text = tc.ToString();
Regards,
Rob Philpott.
|
|
|
|
|
Oh, that's fascinating! Placing a 'd' after a whole number will really make it a double?
|
|
|
|