• 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

    • "TeamViewer is the fast, simple and friendly solution for remote access over the Internet" Regarding the "friendly" description, has is stopped unceremoniusly booting your session after a couple of minutes accusing you of using it in a commercial environment?!
    • I hate religious supremacist genocidal maniacs. How antisemitic of you to imply that's what all Jews are like. Still no links I see. I guess when you're a zionists, backing your claims with proof doesn't matter. bEliEvE mE oR yOuRe hItLeR.
    • Moto G Stylus has better specs and a stylus. Search for the specs to see if they they're important to you. 
    • Funny how people who don't use OneDrive feel the need to give their opinion.
    • Win11Debloat 06.10.2026 by Razvan Serea Win11Debloat is a lightweight, easy to use PowerShell script that allows you to quickly declutter and customize your Windows experience. It can remove pre-installed bloatware apps, disable telemetry, remove intrusive interface elements and much more. The script also includes many features that system administrators and power users will enjoy. Such as a powerful command-line interface, support for Windows Audit mode and the option to make changes to other Windows users. All changes made by Win11Debloat can be easily reversed, and most removed apps can be restored via the Microsoft Store. A full guide on how to undo the changes is available here. Win11Debloat features: Below is an overview of the key features and functionality offered by Win11Debloat. Please refer to the wiki for more information about the default settings preset. Remove a wide variety of preinstalled apps. Click here for more info. Disable telemetry, diagnostic data, activity history, app-launch tracking & targeted ads. Disable tips, tricks, suggestions & ads across Windows. Disable Windows location services & app location access. Disable Find My Device location tracking. Disable 'Windows Spotlight' and tips & tricks on the lock screen. Disable 'Windows Spotlight' desktop background option. Disable ads, suggestions and the MSN news feed in Microsoft Edge. Hide Microsoft 365 ads on the Settings 'Home' page, or hide the 'Home' page entirely. Disable & remove Microsoft Copilot. Disable Windows Recall. Disable Click to Do, AI text & image analysis tool. Prevent AI service (WSAIFabricSvc) from starting automatically. Disable AI Features in Edge. Disable AI Features in Paint. Disable AI Features in Notepad. Disable the Drag Tray for sharing & moving files. Restore the old Windows 10 style context menu. Turn off Enhance Pointer Precision, also known as mouse acceleration. Disable the Sticky Keys keyboard shortcut. Disable Storage Sense automatic disk cleanup. Disable fast start-up to ensure a full shutdown. ...and more. Once you’ve downloaded the Win11Debloat file (Get.ps1), just follow these quick steps: Locate the Get.ps1 script file. Right-click the file and select Run with PowerShell from the context menu. If prompted by User Account Control (UAC), select Yes to grant the script the necessary administrative permissions. Win11Debloat 06.10.2026 release notes: This release brings some long-requested features alongside a host of fixes. For starters, Win11Debloat can now automatically detect previously applied tweaks for the logged-in user. And reverting them is as simple as unchecking the corresponding setting. The script now also fully supports running under the SYSTEM account, which has also made it possible to apply changes to users who are still logged in. This makes it far easier to integrate Win11Debloat into your automations and deployments. What's changed: Add confirmation dialogs & warning for Windows Terminal Removal by @Raphire Add Support for running the script under SYSTEM account by @soccerzockt in #609 With this, support was also added for applying changes to users that are still logged-in. Add option to show & undo previously applied tweaks by @Raphire in #599 Add additional options to change the All Apps view in the start menu (Hide, Grid, Category, List) by @Raphire in #599 Clean up logging of exceptions during Appx Package uninstallation via Write-Verbose by @HetCreep in #617 Improve log output in Get.ps1/Get-Dev.ps1 and clean up file exclusions by @Raphire Remove RemoveCommApps and RemoveW11Outlook app removal parameters. Use -RemoveApps parameter instead by @Raphire in #599 Resolve nested quoting bug in Run.bat when path has spaces, see #583 by @Raphire in #599 Fix desync issue when toggling "Only Show Installed" checkbox too fast by @Raphire in #599 Fix: add missing keys in Sysprep/Undo regfiles for Disabling Recall and Windows Suggested content by @Raphire in #599 Fix 'Disable Animations' Sysprep settings not being set for new users by @Raphire in #599 Fix typo in Disable_Game_Bar_Integration Sysprep registry file by @Raphire Note The -RemoveCommApps and -RemoveW11Outlook command-line parameters for uninstalling a few specific apps have been removed with this release. If you previously relied on these parameters, please see this wiki page for alternative methods of removing these apps. Download: Win11Debloat 06.10.2026 | Open Source View: Win11Debloat Home Page | Screenshots 1| 2 Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      PsYcHoKiLLa
      207
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      89
    5. 5
      ATLien_0
      79
  • Tell a friend

    Love Neowin? Tell a friend!