|
double[] myLottoNums = new double [5];
double sum = 0;
double median = 0;
Console.WriteLine("Please enter five numbers: ");
for (int i = 0; i < 5; i++)
{
Console.Write("Number {0}: ", i+1 );
myLottoNums[i] = double.Parse(Console.ReadLine());
sum = myLottoNums[i] +sum ;
median = (myLottoNums[i]) / myLottoNums.Length;
}
Console.WriteLine("Thank you. The numbers are : ");
foreach (double x in myLottoNums)
{
Console.WriteLine("{0}", x);
}
Console.WriteLine("The sum is {0}",sum);
Console.WriteLine("The median is {0} ", median);
Heres my issue. It sums it fine but the average is 1.2 when it SHOULD BE 6 because 30/5=6 NOT 1.2 . So why is the computer reading it like this?
Thanks like always guys. You guys have been very helpful
|
|
|
|
|
Shouldn't the median be the average of the sum not the current number.
median = sum / myLottoNums.Length;
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
Thank you so much. Yes, I found my mistake. Youre awesome
|
|
|
|
|
If someone here takes their time to assist you, and really helps you solve your problem, or answer your question, it's a very good thing to vote their response up, and it's also a responsible thing to vote down any response you feel is deliberately negative, insulting, or, totally off-topic.
Feedback helps CodeProject build quality.
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
Average != Median.
In statistics and probability theory, the median is the numerical value separating the higher half of a data sample, a population, or a probability distribution, from the lower half.
see here[^]
in the series 6, 9, 2, 7, 1. The median is (1, 2, 6, 7, 9) = 6. The average = (1+2+6+7+9)/5 = 25/5 = 5
So what should be done here is order the five numbers and take the middle one.
|
|
|
|
|
Thank you so much. Thats another mistake I found.
|
|
|
|
|
|
I am catching an exception, and attempting to call out to get the exception pointers in a 32-bit space. This always returns IntPtr.Zero.
When running through 64-bit this returns the propers exception pointers.
Has anyone experienced this or have a possible resolution? I have checked MSDN, nothing of value for this particular scenario. I have googled this but have found nothing helpful as of yet. It does appear there may be solutions in other languages, but I am stuck in C# land and cannot use the others.
Thank you all too much
|
|
|
|
|
Hello. I was given a small project which compiles and runs successfully in Windows 7. I also tested the project on Windows 7. But as soon as I tried to run the project on Windows 8.1, it started giving me said exception.
This definitely is not a programming error. This has something to do with system setting which I can not find out. Here is the code in which exception occurs (calling method is fine) . . .
public static void* Alloc(int size)
{
try
{
static int ph = GetProcessHeap();
void* result = HeapAlloc(ph, HEAP_ZERO_MEMORY, size);
if (result == null)
{
throw new OutOfMemoryException();
}
return result;
}
catch(Exception ex)
{ }
return null;
}
[DllImport("kernel32")]
static extern int GetProcessHeap();
[DllImport("kernel32")]
static extern void* HeapAlloc(int hHeap, int flags, int size);
What could be wrong ?? Thanks for any pointer.
modified 6-Jan-15 4:02am.
|
|
|
|
|
Seeing the statement that causes the error might help. Have you tried the debugger?
|
|
|
|
|
Django_Untaken wrote: This definitely is not a programming error. Most likely it is a programming error, but without seeing the code it's impossible to guess where. Please edit your question and show the code extract where the error occurs, along with the values of the variables that are involved.
|
|
|
|
|
Your question is impossible to answer without knowing what the code is supposed to be doing when it explodes and showing the relevant code.
Most likely this IS a programming error because the code is making a certain assumption about what it can get away with doing under Windows 7 and it can't get away with it under Windows 8.x.
|
|
|
|
|
Django_Untaken wrote: What could be wrong ??
What user do you use on 7.1? What user do you use on 8.1?
How do you run it on the different systems? For example do you install it on both using an installer using default values and then run via that?
|
|
|
|
|
The following code is definitely a programming error and will lead to all sorts of complications:
catch (Exception ex)
{ }
return null;
If an exception occurs it is ignored and the method returns null to the caller, which will probably lead to an access violation.
|
|
|
|
|
Exception is occurring in this method NOT the calling method. Same code is running fine on Windows 7. What happens in Windows 8.1? How do I diagnose this problem ?
|
|
|
|
|
Django_Untaken wrote: Exception is occurring in this method Where, and what are the exact details?
Django_Untaken wrote: Same code is running fine on Windows 7 If the above is an example of the code in this application then I suspect there may be any number of bugs waiting to be found.
|
|
|
|
|
The easiest way is to run the code under the debugger on Win8.
|
|
|
|
|
Aside from the obvious problem of catching and ignoring all exceptions, your P/Invoke declarations are wrong. I suspect the computer that's working is 32-bit, the one that's failing is 64-bit, and your application is compiled as "AnyCPU".
The correct declarations should be:
[DllImport("kernel32.dll")]
static extern IntPtr GetProcessHeap();
[DllImport("kernel32.dll")]
static extern void* HeapAlloc(IntPtr hHeap, uint dwFlags, UIntPtr dwBytes);
(Note the use of IntPtr and UIntPtr instead of int .)
http://pinvoke.net/default.aspx/kernel32/GetProcessHeap.html[^]
http://pinvoke.net/default.aspx/kernel32/HeapAlloc.html[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm using Visual Studio 2012 , is there any way i could get the metro UI for developing Windows Application using C#.
Please note that i need to create a windows application not Windows store App.
Please guide.
|
|
|
|
|
Well, there are some open-source projects, and some commercial components, that simulate the Metro UI for WinForms: [^].
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
|
And what's best is the free one is in VB.
/ravi
|
|
|
|
|
Why shouldn't i try that. is there an issue or something.
Coz i thought that we could make our form look much more professional when compared.
|
|
|
|
|
In my humble opinion, Metro isn't professional. I don't know of 2 people in the same room that like it.
|
|
|
|
|
Can u suggest me an alternative method to make my form look profesional.
|
|
|
|