Drinking Problem in Jokes & Funny Stuff 


Barack Obama enforces US immigration overhaul in Domestic Politics 


Trazodone altering mind into violent? in It's a Conspiracy! 


The Console Wars Are Over, And We Have A Clear Winner in Back Page News 


VGA to Lan via Router via powerline in Hardware Hangout 

Posted 06 January 2013  18:05
Posted 06 January 2013  18:25
int sum = 0; int mean = 0; int median = 0; int num4 = 0; int num5 = 0; for count = 0 to 10 { // For all ten of the user's numbers int num = get_number_from_user(); sum = sum + num; if (count == 4) num4 = num; // If this is one of the two middle numbers, store it for calculating the median if (count == 5) num5 = num; } mean = sum / 10; // EDIT: See discussion below about calculating the median if the numbers aren't entered in order //median = (num4 + num5) / 2; // Two middle numbers so the median is their average print(sum + " " + mean + " " + median);
Posted 06 January 2013  18:34
Don't know what language you're using so I can't make it particularly specific:
int sum = 0; int mean = 0; int median = 0; int num4 = 0; int num5 = 0; for count = 0 to 10 { // For all ten of the user's numbers int num = get_number_from_user(); sum = sum + num; if (count == 4) num4 = num; // If this is one of the two middle numbers, store it for calculating the median if (count == 5) num5 = num; } mean = sum / 10; median = (num4 + num5) / 2; // Two middle numbers so the median is their average print(sum + " " + mean + " " + median);
int sum = 0; int mean = 0; int median = 0; int count = 10; int num[] = {0}; for int N = 1 to count { num[N] = get_number_from_user(); sum += num[N]; } mean = sum / count; sort(num[]); median = (num[5] + num[6]) / 2; print(sum + " " + mean + " " + median);
Posted 06 January 2013  18:35
On a more serious note, it looks like you want your homework problem solved. Rather than handing it on a silver plate, would you mind showing us how far you've got already?
You are making the assumption that the user will input numbers in ascending numerical order.
...
I would suggest it needs to sort the numbers into ascending numerical order before trying to calculate the median.
Posted 07 January 2013  17:18
Posted 07 January 2013  20:31
Posted 08 January 2013  20:23
so i could write it like this...
Calculate the MEDIAN and store = ((Number 5 + Number 6 ) / 2)
Posted 08 January 2013  20:50
FWIW, 5 + 6 is relative to the starting number. If you were just shoving the input into an array, it would be 0  9, and the median would be (4+5)/2. Unless specified, I would assume any pseudocode to count from zero.
Posted 08 January 2013  21:27
Posted 08 January 2013  22:26
Must have meant array indexing  zerobased or onebased. Zerobased being very prevalent, but nevertheless not universal. We must not make assumptions  the very idea of pseudocode (of informal syntax) is meant to be readable (so onebased would be more natural) and easy to translate among different languages (even though *we* know that VB, zerobased, will be used).
If anything, writing only the definition of median would be the most acceptable.
Posted 09 January 2013  01:08
Must have meant array indexing  zerobased or onebased. Zerobased being very prevalent, but nevertheless not universal. We must not make assumptions  the very idea of pseudocode (of informal syntax) is meant to be readable (so onebased would be more natural) and easy to translate among different languages (even though *we* know that VB, zerobased, will be used).
If anything, writing only the definition of median would be the most acceptable.