![]() |
|
[C#] C# easy homework, math not working. int equal = numbers.max()-numbers.min() <- ?? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] C# easy homework, math not working. int equal = numbers.max()-numbers.min() <- ?? (/showthread.php?tid=2175883) |
C# easy homework, math not working. int equal = numbers.max()-numbers.min() <- ?? - svavart - Feb 3, 2012 The following code won't show the correct answer. (Suppose to show the answer to highest number - lowest number.) code: Code string texti = textBox1.Text;* - Silicon - Feb 3, 2012 Change this line: Code int[] tolur = new int[texti.Length];Code int[] tolur = new int[tolur.Length];* - svavart - Feb 3, 2012 (Feb 3, 2012 01:24 PM)AntiHelix Wrote: Change this line:Just got an error "the use of an unassigned variable" By the way that line I use to be sure the array has enough "compartments" for the numbers in the textbox1 which are separated by a ",". Everything works, even the .max number and the .min numbers are correct it's just that the subtraction doesn't seem to work. =/ //full code with irrelevant stuff Code using System;* - Gh0st-Zer0 - Feb 3, 2012 This is the working code for UInt64 numbers which mean that you can insert From 0 to 18,446,744,073,709,551,615 which equals 2^64 − 1 numbers. I have also commented the code so to be understandable. This is Consoled based algorythm just change it and modify it into your app! Code //First of all we need UInt64 to calculate really long numbers.Execution Result: Code Were read into the numbers:* - E25EB8582FF05BF - Feb 3, 2012 @Ghost. Should we read your sound and well in code commented answer as a sign you're irritated by the lack of self involvement of those lazy "students" expecting us to do their homework ? * - svavart - Feb 3, 2012 (Feb 3, 2012 05:12 PM)Gh0st-Zer0 Wrote: This is the working code for UInt64 numbers which mean that you can insert From 0 to 18,446,744,073,709,551,615 which equals 2^64 − 1 numbers.The teacher didn't go in dept about what the usual "int" was capable to do so thanks ;), also thanks for taking time to comment the code. Too many that decide not to. tolur = numbers texti = text strengur = string Forgot to include. * - Gh0st-Zer0 - Feb 3, 2012 (Feb 3, 2012 06:46 PM)E25EB8582FF05BF Wrote: @Ghost. Should we read your sound and well in code commented answer as a sign you're irritated by the lack of self involvement of those lazy "students" expecting us to do their homework ?Well he did the half job so i just help a little to complete! Of course i'm not the guy that support lazy Students! I'm a Univercity student and i hate guys that C/P other work and present them us theirs! * - Silicon - Feb 4, 2012 Sorry for my last post, I was tired and I changed it to the wrong variable. Change this line: Code int[] tolur = new int[texti.Length];Code int[] tolur = new int[strengur.Length];If you set it to texti.Length, you are setting the array size to the amount of characters in the text box. What if you had a 10-digit-long number, but only that number? Then you'd have 10 spaces in the array, but only working with 1 number. Because strengur is the text split up via ,, you are setting it to the number of items separated by ,s in the text. * - svavart - Feb 4, 2012 (Feb 3, 2012 06:59 PM)Gh0st-Zer0 Wrote: Well he did the half job so i just help a little to complete! Of course i'm not the guy that support lazy Students! I'm a Univercity student and i hate guys that C/P other work and present them us theirs! I'm at the early stage of learning the programming basics with c# and there are already plenty of students to lazy to do their own work. Unfortunately for them there is a program that cross-checks all the students projects when you've made it to advanced programming. (Feb 4, 2012 03:43 AM)AntiHelix Wrote: If you set it to texti.Length, you are setting the array size to the amount of characters in the text box. What if you had a 10-digit-long number, but only that number? Then you'd have 10 spaces in the array, but only working with 1 number. Because strengur is the text split up via ,, you are setting it to the number of items separated by ,s in the text.Thanks, I understand what you mean now, feel a bit stupid for not noticing that. ;) * - Gh0st-Zer0 - Feb 4, 2012 (Feb 4, 2012 04:56 AM)svavart Wrote: I'm at the early stage of learning the programming basics with c# and there are already plenty of students to lazy to do their own work. Unfortunately for them there is a program that cross-checks all the students projects when you've made it to advanced programming.Well if it's like that. . . Good Then! 🙂 |