• 0

Pseudocode help


Question

Hi guys just wanted some help with Pseudocode. I just can get my head around it all I dont know why but I am really struggling. I have been asked to do the following. A program is needed that can accept 10 numbers as input from the user. The program should output the following information:

The sum of the numbers,

The mean of the numbers,

The median value for the numbers

any pointers

thanks

Link to comment
https://www.neowin.net/forum/topic/1129406-pseudocode-help/
Share on other sites

14 answers to this question

Recommended Posts

  • 0

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;
// 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);[/CODE]

  • 0

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);[/CODE]


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.
Something like:
[code]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);

  • 0

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?

He asked for pseudocode instead of a solution which is certainly better than the average homework question around here. You still have to know what you're doing to a reasonable degree to get anything working from it.

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.

True, not sure why I was assuming they were sorted. Thanks for pointing that out.

  • 0

Im not asking for my homework to be done but a few pointers as I have been told that writing in pseudocode is the step in between the flow chart and the programming code, So when a programmer can look at this and they can make determine what I want.

The code I'm going to be using is VB.

This is what I have done so far.

BEGIN

PROMPT ?Enter Numbers?

ADD and STORE Numbers = SUM

ARRANGE Numbers in Ascending order

Calculate MEAN of Numbers and STORE = SUM / 10

Calculate the MEDIAN and store = Number 5 + Number 6 / 2

PRINT SUM

PRINT MEAN

PRINT MEDIAN

END

Can you tell me what you think.

thanks

  • 0

Then please accept my apologies.

Yes, that's more like pseudocode - unrelated to any language in particular, understandable even to a non-programmer.

In classes we quickly went to Pascal syntax to get closer to the code, but flowcharts seem so much easier to do if one stays with informal syntax such as this.

Some comments:

* Even when using informal syntax, division takes precedence over addition. So the Number 5 + Number 6 / 2 line is confusing, and might creep an error in code later, if one is not careful. Either use parenthesis outright or just write the definition of median - mean of the two middlemost numbers.

* Regardless of syntax, SORT would be probably be better term instead of ARRANGE. Using engineering terms still helps if you later have to elaborate on how exactly one does that (all algorithms "sort")

  • 0

so i could write it like this...

Calculate the MEDIAN and store = ((Number 5 + Number 6 ) / 2)

That's fine but the outer brackets are redundant. Wrapping the entire equation in brackets is the same as having none, so ((Number 5 + Number 6) / 2) is the same as (Number 5 + Number 6) / 2.

  • 0

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.

Not sure if I'm misunderstanding what you're saying or if I'm just confused by your explanation, but the median is worked out as follows:-

1. Sort the numbers into ascending order.

2. If the number of numbers is odd, the median is the middle number.

3. If the number of numbers is even, the median is the mean of the middle two numbers.

Example 1:

1, 2, 3, 10, 11 - the median is 3 because it's the middle number.

Example 2:

1, 2, 3, 4, 10, 11 - median is 3.5, because you take the middle two numbers and work out the mean. (3 + 4) / 2 = 3.5.

  • 0

Must have meant array indexing - zero-based or one-based. Zero-based 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 one-based would be more natural) and easy to translate among different languages (even though *we* know that VB, zero-based, will be used).

If anything, writing only the definition of median would be the most acceptable.

  • 0

Must have meant array indexing - zero-based or one-based. Zero-based 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 one-based would be more natural) and easy to translate among different languages (even though *we* know that VB, zero-based, will be used).

If anything, writing only the definition of median would be the most acceptable.

Just reread his post and I agree he was probably talking about array indexing.

Pseudo code being language independent and supposed to be readable, I thought it would make more sense to use a one-based array. Clearly when translating it into actual code the user must make the necessary adjustments if it is a zero-based language.

  • 0

Must have meant array indexing - zero-based or one-based. Zero-based 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 one-based would be more natural) and easy to translate among different languages (even though *we* know that VB, zero-based, will be used).

If anything, writing only the definition of median would be the most acceptable.

Well, you know that 10 is going to be the number of inputs as well.

You could say MEDIAN = LENGTH OF ARRAY MODULO 2 ? ROUND UP ARRAY[LENGTH/2] : (ARRAY[LENGTH/2] + ARRAY[LENGTH/2 + 1]) / 2

Thereby negating the need to know the index or the number of inputs and defining median.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Dragon's Dogma 2: Dark Arisen expansion to bring snowy region, new updates also coming by Pulasthi Ariyasinghe Capcom had a surprise waiting for Dragon's Dogma fans today in the Nintendo Direct presentation. The company revealed an expansion for the second installment with a name that should be familiar to series veterans. Coming later this year, Dragon's Dogma 2: Dark Arisen is promising a massive new region to explore, new monsters, fresh skills to learn, and more. The studio says players will be heading to the Northern region of the world, named Norgan, to find new secrets about an undying "Fallen Dragon." There will be forgotten relics that the protagonist can find to unlock fresh weapons and skills the expansion is introducing. Players will also be able to find mysterious equipment from a previous Arisen as a part of the expansion, all part of 12 Lost Rites Dungeon Challenges they must complete to gain access. In Neowin's own review, I found Dragon's Dogma 2 to be an impressive RPG when it launched back in 2024, giving the title an 8.5/10 for its class variants, companion system, and immersive exploration. "Once a prosperous region of the kingdom of Vermund, it was abandoned many years ago for reasons unknown," says Capcom about the new region. "Long has it been since any soul traveled its paths. Blanketed in heavy snow, these frigid lands are home to savage hordes and creatures of unbelievable power. Those who are capable of vanquishing such fearsome foes, or those who possess a keen eye for exploration, will find themselves rewarded with powerful relics." Dragon’s Dogma 2: Dark Arisen expansion launches on October 9, 2026, with a $29.99 price tag. Ahead of the expansion release, Capcom is also planning to release two free updates to the base game. The first will land tomorrow, June 10, bringing more accessible fast travel with an Eternal Ferrystone and other quality-of-life adjustments. The second update will land sometime in August, aiming to improve frame rates, add more save slots, and bring even more community-requested adjustments. This expanded Dark Arisen edition is also launching on the Nintendo Switch 2 on the same day the content comes to PC, Xbox Series X|S, and PlayStation 5.
    • Classic themes are just the colors on the bar like the olden days, if you use the image themes, it does fancy transparent backgrounds and it makes the elements of the app look like they are transparent bubbles. This sample image shows what it looks like.  
    • Good point, unfortunately. NextDNS has far more filters and workarounds than uBlock, and it's easy to implement.
    • Windows 10 KB5094127 Patch Tuesday improves File Explorer search and more by Taras Buria The June 2026 Patch Tuesday updates are here, bringing mandatory patches to users with PCs enrolled in the Extended Security Update program for Windows 10. Microsoft is rolling out KB5094127, with build numbers 19045.7417 and 19044.7417. Changelog includes the following: [File Explorer] This update improves File Explorer search, including support for Chinese text, and UTF 8–encoded files without a byte order mark (BOM). Text now displays more clearly and consistently across search results, Content view, and tooltips. [Secure Boot] This update enables dynamic status reporting for Secure Boot states in Windows Security App. This update adds a new policy setting, LimitSecureBootRequiredServiceData, under Computer Configuration > Administrative Templates > Windows Components > Secure Boot. When this setting is enabled, Windows limits the Secure Boot service data it sends by suppressing the event normally sent to Microsoft. This policy is also included in the Windows Restricted Traffic Limited Functionality Baseline package. For information about the policy, see Manage connections from Windows 10 and Windows 11 operating system components to Microsoft services. With this update, Windows quality updates include additional high confidence device targeting data, increasing coverage of devices eligible to automatically receive new Secure Boot certificates. Devices receive the new certificates only after demonstrating sufficient successful update signals, maintaining a controlled and phased rollout. As for known bugs, Microsoft has the following to say: A workaround is available in the official documentation. Today's updates are available for PCs enrolled in the Extended Security Updates program only. If your PC is eligible, you can download the update from Settings > Windows Update or from the Microsoft Update Catalog here.
    • Then the solution is to not let children have easy access to smart phones or internet until they are older, not mass surveillance. Only this would require parents to do actual parenting, most likely, as with any good solution to the problem.
  • Recent Achievements

    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • One Year In
      jojodbn earned a badge
      One Year In
    • One Month Later
      jojodbn earned a badge
      One Month Later
    • Week One Done
      jojodbn earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      522
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      124
    4. 4
      ATLien_0
      87
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!